nanozuki / tabby.nvim

A declarative, highly configurable, and neovim style tabline plugin. Use your nvim tabs as a workspace multiplexer!
MIT License
570 stars 20 forks source link

[Bug] highlight group not found: TabbyHl___ #59

Closed luiz00martins closed 2 years ago

luiz00martins commented 2 years ago

I'm getting an error when starting tabby:

Error detected while processing function TabbyTabline:                                                                                          
line    1:                                                                                                                                      
E5108: Error executing lua ...packer/start/tabby.nvim/lua/tabby/internal/highlight.lua:29: Vim(highlight):E411: highlight group not found: TabbyHl___                                                                                                                                           
stack traceback:                                                                                                                                
        [C]: in function 'cmd'                                                                                                                  
        ...packer/start/tabby.nvim/lua/tabby/internal/highlight.lua:29: in function 'register'                                                  
        ...ck/packer/start/tabby.nvim/lua/tabby/internal/render.lua:93: in function 'highlight'                                                 
        ...ck/packer/start/tabby.nvim/lua/tabby/internal/render.lua:67: in function 'frag'                                                      
        ...ck/packer/start/tabby.nvim/lua/tabby/internal/render.lua:24: in function 'node'                                                      
        ...ck/packer/start/tabby.nvim/lua/tabby/internal/render.lua:65: in function
<...ck/packer/start/tabby.nvim/lua/tabby/internal/render.lua:57>                                                                                                                                            
        vim/shared.lua: in function 'tbl_map'                                                                                                   
        .../site/pack/packer/start/tabby.nvim/lua/tabby/tabline.lua:146: in function 'update'                                                   
        [string "luaeval()"]:1: in main chunk

It's quite inconsistent. It only happens on some startups, in others it just runs fine (feels like 50/50 chance). When the error happens, the tabline does not load correctly. Here's some screenshots of how the tab normally looks like, and how it looks like with the error: normal buggy

This is my full config:

local filename = require('tabby.filename')
local util = require('tabby.util')

local hl_tabline = util.extract_nvim_hl('TabLine')
local hl_tabline_sel = util.extract_nvim_hl('TabLineSel')
local hl_tabline_fill = util.extract_nvim_hl('TabLineFill')

local function tab_label(tabid, active)
    local icon = active and '' or ''
    local number = vim.api.nvim_tabpage_get_number(tabid)
local name = util.get_tab_name(tabid)
    if active then
        return string.format(' %s %d: %s ', icon, number, name)
    else
        return string.format(' %s %d ', icon, number)
    end
end

local tabline = {
    hl = 'TabLineFill',
    layout = 'tab_only',
    head = {
        { '  ', hl = { fg = hl_tabline.fg, bg = hl_tabline.bg } },
        { '', hl = { fg = hl_tabline.bg, bg = hl_tabline_fill.bg } },
    },
    active_tab = {
        label = function(tabid)
            return {
                tab_label(tabid, true),
                hl = { fg = hl_tabline_sel.fg, bg = hl_tabline_sel.bg, style = 'bold' },
            }
        end,
        left_sep = { '', hl = { fg = hl_tabline_sel.bg, bg = hl_tabline_fill.bg } },
        right_sep = { '', hl = { fg = hl_tabline_sel.bg, bg = hl_tabline_fill.bg } },
    },
    inactive_tab = {
        label = function(tabid)
            return {
                tab_label(tabid, false),
                hl = { fg = hl_tabline.fg, bg = hl_tabline.bg, style = 'bold' },
            }
        end,
        left_sep = { '', hl = { fg = hl_tabline_fill.bg, bg = hl_tabline_fill.bg } },
        right_sep = { '', hl = { fg = hl_tabline_fill.bg, bg = hl_tabline_fill.bg } },
    },
    top_win = {
        label = function(winid)
            return {
                --' > ' .. filename.unique(winid) .. ' ',
                '',
                hl = 'TabLine',
            }
        end,
        left_sep = { ' ', hl = 'TabLineFill' },
    },
    win = {
        label = function(winid)
            return {
                --' - ' .. filename.unique(winid) .. ' ',
                '',
                hl = 'TabLine',
            }
        end,
        left_sep = { ' ', hl = 'TabLineFill' },
    },
}

require('tabby').setup({
    tabline = tabline,
})
luiz00martins commented 2 years ago

In case you cannot repro...

Debugging info

With this config, the plugin works, but the colors are inconsistent:

local filename = require('tabby.filename')
local util = require('tabby.util')

local hl_tabline = util.extract_nvim_hl('TabLine')
local hl_tabline_sel = util.extract_nvim_hl('TabLineSel')
local hl_tabline_fill = util.extract_nvim_hl('TabLineFill')

local function tab_label(tabid, active)
    local icon = active and '' or ''
    local number = vim.api.nvim_tabpage_get_number(tabid)
    local name = util.get_tab_name(tabid)
    if active then
        return string.format(' %s %d: %s ', icon, number, name)
    else
        return string.format(' %s %d ', icon, number)
    end
end

local tabline = {
    hl = 'TabLineFill',
    layout = 'tab_only',
    -- REMOVED HEAD
    active_tab = {
        label = function(tabid)
            return {
                tab_label(tabid, true),
                hl = { fg = hl_tabline_sel.fg, bg = hl_tabline_sel.bg, style = 'bold' },
            }
            -- REMOVED SEP
        end,
    },
    inactive_tab = {
        label = function(tabid)
            return {
                tab_label(tabid, false),
                hl = { fg = hl_tabline.fg, bg = hl_tabline.bg, style = 'bold' },
            }
            -- REMOVED SEP
        end,
    },
    top_win = {
        label = function(winid)
            return {
                --' > ' .. filename.unique(winid) .. ' ',
                '',
                hl = 'TabLine',
            }
        end,
        left_sep = { ' ', hl = 'TabLineFill' },
    },
    win = {
        label = function(winid)
            return {
                --' - ' .. filename.unique(winid) .. ' ',
                '',
                hl = 'TabLine',
            }
        end,
        left_sep = { ' ', hl = 'TabLineFill' },
    },
}

require('tabby').setup({
    tabline = tabline,
})

normal_color weird_color

Same results (inconsistent colors) with this simpler one:

local filename = require('tabby.filename')
local util = require('tabby.util')

local hl_tabline = util.extract_nvim_hl('TabLine')
local hl_tabline_sel = util.extract_nvim_hl('TabLineSel')
local hl_tabline_fill = util.extract_nvim_hl('TabLineFill')

local function tab_label(tabid, active)
    local icon = active and '' or ''
    local number = vim.api.nvim_tabpage_get_number(tabid)
    local name = util.get_tab_name(tabid)
    if active then
        return string.format(' %s %d: %s ', icon, number, name)
    else
        return string.format(' %s %d ', icon, number)
    end
end

local tabline = {
    hl = 'TabLineFill',
    layout = 'tab_only',
    active_tab = {
        label = function(tabid)
            return {
                tab_label(tabid, true),
                hl = { fg = hl_tabline_sel.fg, bg = hl_tabline_sel.bg, style = 'bold' },
            }
        end,
    },
}

require('tabby').setup({
    tabline = tabline,
})

However, more bizarrely, if I complete remove all options, the error returns. The config below yields the error again:

require('tabby').setup({})
nanozuki commented 2 years ago

Thanks for your feedback, I will do some tests in this week.

yitsushi commented 2 years ago

Note: It was introduced somewhere in the the commits on May/10 or May/11, I last synced around end of April, today I synced plugins and it's there.

yitsushi commented 2 years ago

Went through the commits one by one and called PackerUpdate, the first commit where I can see the error: https://github.com/nanozuki/tabby.nvim/commit/7866ad70f87293ab64bf443c61f38c695b7f3a78

I'm not good enough with lua to figure out why 😆

Until fixed:

use {
  "nanozuki/tabby.nvim",
  commit = 'fcbd6ee548e8e8ce0e409d0727bd198d2ff17098',
....
}
nanozuki commented 2 years ago

@yitsushi After I read the code, I think maybe this is the bug I fixed in the latest commit. May you try the latest commit and test it again?

moevis commented 2 years ago

I got the same problem with latest code.

I just use default config likes following:

require"tabby".setup({})

and here is the output:

line    1:
E5108: Error executing lua ...packer/start/tabby.nvim/lua/tabby/internal/highlight.lua:29: Vim(highlight):E411: highlight group not found: TabbyHl___
stack traceback:
        [C]: in function 'cmd'
        ...packer/start/tabby.nvim/lua/tabby/internal/highlight.lua:29: in function 'register'
        ...ck/packer/start/tabby.nvim/lua/tabby/internal/render.lua:93: in function 'highlight'
        ...ck/packer/start/tabby.nvim/lua/tabby/internal/render.lua:67: in function <...ck/packer/start/tabby.nvim/lua/tabby/internal/render.lua:57>
        vim/shared.lua: in function 'tbl_map'
        .../site/pack/packer/start/tabby.nvim/lua/tabby/tabline.lua:146: in function 'update'
        [string "luaeval()"]:1: in main chunk

In addtion, when I initialized the plugin without a map param

require"tabby".setup()

I got these error:

Error detected while processing /Users/bytedance/.config/nvim/init.lua:
E5113: Error while calling lua chunk: vim/shared.lua:0: after the second argument: expected table, got nil
stack traceback:
        [C]: in function 'error'
        vim/shared.lua: in function 'validate'
        vim/shared.lua: in function 'tbl_extend'
        ...vim/site/pack/packer/start/tabby.nvim/lua/tabby/init.lua:14: in function 'setup'
        /Users/bytedance/.config/nvim/init.lua:572: in main chunk

My neovim version is

NVIM v0.7.0 Build type: Release LuaJIT 2.1.0-beta3 Compiled by runner@Mac-1650023513425.local

on macOS 12.4

moevis commented 2 years ago

After I tried several presets, I found this config seems to have no error throwed.

require"tabby".setup({
    tabline = require("tabby.presets").tab_with_top_win,
})

But the apperance is strange:

Screen Shot 2022-05-30 at 16 33 23

Following presets will throw error: highlight group not found: TabbyHl___

active_wins_at_tail
active_tab_with_wins
tab_only
nanozuki commented 2 years ago

@yitsushi @moevis, thanks for the feedback! After I remove all themes, I reproduce this bug. I'll fix this in days. Sadly, My mini-config for testing has a theme. So I can't find this issue 😂

nanozuki commented 2 years ago

I fixed it; I used the wrong way to get Highlight. If there are more compatibility issues, welcome to tell me.

yitsushi commented 2 years ago

I can confirm, updated to the latest commit and no errors on my side (with the same setup I had before)

luiz00martins commented 2 years ago

Yep the TabbyHl__ error is gone!

I'm still getting the wrong highlight sometimes though. Same error as I mentioned in my "debugging info". Sometimes I get the right highlight, sometimes it uses a (wrong) gray color. Here's an example with my full config (in the original issue): Screenshot from 2022-06-01 11-55-02 Screenshot from 2022-06-01 11-55-41

The chances of this happening looks exactly like the chances of me getting the original one, about 50/50.

Also these were mutually exclusive. By that I mean that, depending on the config, I would either get one, or the other (i.e. they would replace one another). So, I have high suspicions that these two are related.

anstadnik commented 2 years ago

I can confirm wrong highlights image

nanozuki commented 2 years ago

@luiz00martins One scenario I've found that causes this is the order in which tabby and theme are launched. May you use packer, try to use the after option as a workaround? I would to explore a nice way to improve this.

nanozuki commented 2 years ago

@anstadnik Oh, May you tell me what theme you use?

anstadnik commented 2 years ago

@nanozuki sure :)

minimal init.lua ```lua vim.g.python3_host_prog = '/home/astadnik/.virtualenvs/neovim/bin/python3' local install_path = vim.fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim' if vim.fn.empty(vim.fn.glob(install_path)) > 0 then vim.fn.termopen(('git clone --depth 1 https://github.com/wbthomason/packer.nvim %q'):format(install_path)) end require('packer').startup({ function(use) use { 'rmehri01/onenord.nvim', config = [[require 'plugins.onenord']] } use { "nanozuki/tabby.nvim", config = [[require("tabby").setup({ tabline = require("tabby.presets").active_tab_with_wins })]] } end}) % vim.o.background='light' ```

The error occurs when changing the background, and sometimes persists (maybe when multiple nvim instances are opened)

anstadnik commented 2 years ago

Oh you maybe would want to see onenord.lua.

onenord.lua ```lua -- Colorscheme require('onenord').setup({ fade_nc = true, -- Fade non-current windows, making them more distinguishable -- Style that is applied to various groups: see `highlight-args` for options styles = { comments = "italic", strings = "italic", keywords = "bold", functions = "NONE", variables = "NONE", diagnostics = "undercurl", }, disable = { background = false, -- Disable setting the background color cursorline = false, -- Disable the cursorline eob_lines = true, -- Hide the end-of-buffer lines }, -- Inverse highlight for different groups inverse = { match_paren = true, }, }) ```
luiz00martins commented 2 years ago

@luiz00martins One scenario I've found that causes this is the order in which tabby and theme are launched. May you use packer, try to use the after option as a workaround? I would to explore a nice way to improve this.

Tried it, with no luck. Got the same problem with the following use clause:

use {
    'nanozuki/tabby.nvim',
    after = 'folke/tokyonight.nvim',
}
nanozuki commented 2 years ago

@luiz00martins What about your whole config, including the plugin manager's setting? Do you put the config of tabby.nvim in the packer's plugin declaration? Like this:

use {
  'nanozuki/tabby.nvim',
  config = function()
    require('tabby').setup({})
  end
}
luiz00martins commented 2 years ago

I already showed my whole tabby config, it's in the original issue (and it's definetely being called, although manually, not in config).

See my previous comments. I posted a lot of configs I tested, and a lot of screeshots of the results.

My whole config is the use clause:

use {
    'nanozuki/tabby.nvim',
    after = 'tokyonight.nvim',
}

followed by the actual config, which is wrapped in a function:

plugin_configs['tabby'] = function()
    local filename = require('tabby.filename')
    local util = require('tabby.util')

    local hl_tabline = util.extract_nvim_hl('TabLine')
    local hl_tabline_sel = util.extract_nvim_hl('TabLineSel')
    local hl_tabline_fill = util.extract_nvim_hl('TabLineFill')

    local function tab_label(tabid, active)
        local icon = active and '' or ''
        local number = vim.api.nvim_tabpage_get_number(tabid)
        local name = util.get_tab_name(tabid)
        if active then
            return string.format(' %s %d: %s ', icon, number, name)
        else
            return string.format(' %s %d ', icon, number)
        end
    end

    local tabline = {
        hl = 'TabLineFill',
        layout = 'tab_only',
        head = {
            { '  ', hl = { fg = hl_tabline.fg, bg = hl_tabline.bg } },
            { '', hl = { fg = hl_tabline.bg, bg = hl_tabline_fill.bg } },
        },
        active_tab = {
            label = function(tabid)
                return {
                    tab_label(tabid, true),
                    hl = { fg = hl_tabline_sel.fg, bg = hl_tabline_sel.bg, style = 'bold' },
                }
            end,
            left_sep = { '', hl = { fg = hl_tabline_sel.bg, bg = hl_tabline_fill.bg } },
            right_sep = { '', hl = { fg = hl_tabline_sel.bg, bg = hl_tabline_fill.bg } },
        },
        inactive_tab = {
            label = function(tabid)
                return {
                    tab_label(tabid, false),
                    hl = { fg = hl_tabline.fg, bg = hl_tabline.bg, style = 'bold' },
                }
            end,
            left_sep = { '', hl = { fg = hl_tabline_fill.bg, bg = hl_tabline_fill.bg } },
            right_sep = { '', hl = { fg = hl_tabline_fill.bg, bg = hl_tabline_fill.bg } },
        },
        top_win = {
            label = function(winid)
                return {
                    --' > ' .. filename.unique(winid) .. ' ',
                    '',
                    hl = 'TabLine',
                }
            end,
            left_sep = { ' ', hl = 'TabLineFill' },
        },
        win = {
            label = function(winid)
                return {
                    --' - ' .. filename.unique(winid) .. ' ',
                    '',
                    hl = 'TabLine',
                }
            end,
            left_sep = { ' ', hl = 'TabLineFill' },
        },
    }

    require('tabby').setup({
        tabline = tabline,
    })
end

which is eventually called:

plugin_configs['tabby']()

And I'd love to debug it more, but I'm being blocked by #64


Edit: #64 was resolved, and I can confirm that the after clause does not solve the HL problem.

nanozuki commented 2 years ago

The key point of this question is:

The sentence local hl_tabline = util.extract_nvim_hl('TabLine') should be called after theme loaded. If not, you will get the wrong color. Mentions, not the tabby should be loaded after the theme, is this util.extract_nvim_hl should be called after the theme is loaded.

This is why I need the whole neovim config if I want to figure out the problem. If you use packer, you should add config to the plugin declaration, so packer will confirm the config runner after the plugin is loaded. It will delay the calling of function util.extract_nvim_hl.

If your config is too large, you can try to write a minimal config to reproduce it.

luiz00martins commented 2 years ago

The sentence local hl_tabline = util.extract_nvim_hl('TabLine') should be called after theme loaded. If not, you will get the wrong color.

That's it! Making sure that runs after setting the colorscheme fixes the problem. Thanks.

If tabby currently pulls in "hard values" from the colorscheme, maybe linking to the HL group instead could fix this behaviour.

nanozuki commented 2 years ago

Because the separator's highlight is calculated from two highlights, I can't link directly. I'm exploring a new way to get highlights.

anstadnik commented 2 years ago

Am I understanding correctly that the current approach won't allow theme or (more importantly background) change while nvim is already running?

nanozuki commented 2 years ago

Am I understanding correctly that the current approach won't allow theme or (more importantly background) change while nvim is already running?

For current preset configs, it is. I'm writing the next version of tabby, It has a better way to automatically handle color scheme changing.