nanozuki / tabby.nvim

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

Getting error when opening new tab #145

Open shaeinst opened 5 days ago

shaeinst commented 5 days ago

error log

Error detected while processing function TabbyRenderTabline:                                                                    
line    1:                                                                                                                      
E5108: Error executing lua ...vim/lazy/plugins/tabby.nvim/lua/tabby/module/builder.lua:88: hl: expected string|table, got nil   
stack traceback:                                                                                                                
        [C]: in function 'error'                                                                                                
        vim/shared.lua: in function 'validate'                                                                                  
        ...vim/lazy/plugins/tabby.nvim/lua/tabby/module/builder.lua:88: in function 'parse_highlight'                           
        ...vim/lazy/plugins/tabby.nvim/lua/tabby/module/builder.lua:104: in function 'render_element'                           
        ...share/nvim/lazy/plugins/tabby.nvim/lua/tabby/tabline.lua:52: in function 'render'                                    
        [string "luaeval()"]:1: in main chunk  
nanozuki commented 5 days ago

Can you share with me your config of tabby.nvim and the colorscheme you use?

shaeinst commented 4 days ago

sure, i should have shared it in the first place. sorry.

SOURCE

local spec = {
    "nanozuki/tabby.nvim",
}

local tab = function()
    local tabs = tostring(#vim.api.nvim_list_tabpages())
    local tabpage = tostring(vim.api.nvim_tabpage_get_number(0))
    return tabpage .. "/" .. tabs
end

-- By default, Tabby counts all windows, resulting in the same name being repeatedly displayed.
-- This function addresses the issue by merging the duplicates.
local function wins_in_tab(line, theme)
    local unique_buffers = {}

    return line.wins_in_tab(line.api.get_current_tab()).foreach(function(win)
        local buf_name = win.buf_name()
        unique_buffers[buf_name] = unique_buffers[buf_name] or { is_current = false, lines = {} }
        unique_buffers[buf_name].is_current = unique_buffers[buf_name].is_current or win.is_current()

        if not vim.tbl_contains(unique_buffers[buf_name].lines, buf_name) then
            table.insert(unique_buffers[buf_name].lines, buf_name)
            local is_same_buff = vim.fn.bufnr(buf_name) == vim.fn.bufnr()

            local icon = " " .. win.file_icon() .. " "
            -- local icon = is_same_buff and "  " or "  "
            local hl = is_same_buff and theme.current_win or theme.win

            return {
                line.sep("", theme.win, theme.fill),
                icon,
                buf_name,
                line.sep("", theme.win, theme.tab),
                hl = hl,
                margin = "",
            }
        end
    end)
end

local theme = {
    fill = "TabLineFill",
    head = "TabLine",
    current_tab = "TabLineSel",
    tab = "TabLine",
    win = "TabLine",
    current_win = "TabLineCurrentWin",
    tail = "TabLine",
}

local view = function(line)
    return {
        {
            { tab(), hl = theme.head },
            line.sep(" ", theme.head, theme.tab),
        },
        line.tabs().foreach(function(tab)
            local hl = tab.is_current() and theme.current_tab or theme.tab
            return {
                -- line.sep(" ", hl, theme.fill),
                -- tab.is_current() and " " or "󰆣 ",
                -- " " .. tab.number(),
                " ",
                tab.name(),
                " ",
                -- tab.close_btn(" "),
                -- line.sep(" ", hl, theme.tab),
                hl = hl,
                -- margin = " ",
            }
        end),
        line.sep(" ", theme.head, theme.tab),
        line.spacer(),
        wins_in_tab(line, theme),
        -- {
        --  line.sep("", theme.tail, theme.fill),
        --  { "  ", hl = theme.tail },
        -- },
        -- hl = theme.fill,
    }
end

local opt = {
    buf_name = {
        mode = "unique", -- 'unique'|'relative'|'tail'|'shorten'
    },
}

spec.config = function()
    -- Save and restore in session
    -- You can save and restore tab layout and tab names in session, by adding word tabpages(for layout)
    -- and globals(for tab names) to vim.opt.sessionoptions. This is a valid sessionoptions:
    vim.opt.sessionoptions = "curdir,folds,globals,help,tabpages,terminal,winsize"
    -- At default, neovim only display tabline when there are at least two tab pages. If you want always display tabline:
    vim.o.showtabline = 1

    require("abstract.utils.map").set_plugin("nanozuki/tabby.nvim")
    require("tabby.tabline").set(view, opt)
end

return spec