From 98dc2dd3a2a07c251bcbd43048157aa56f901402 Mon Sep 17 00:00:00 2001 From: shadmansaleh <13149513+shadmansaleh@users.noreply.github.com> Date: Mon, 7 Feb 2022 22:13:42 +0600 Subject: [PATCH] fix: LualineRenameTab crashing lualine fixes https://github.com/nvim-lualine/lualine.nvim/pull/574#pullrequestreview-874872853 Issue was neovim's tabpage handle used by rpc-api isn't same as tab no in viml. Now the tabpage handle is stores in self.tabId and tab no is stored in self.tabnr in `Tab` so any can be used when necessary. --- lua/lualine/components/tabs/init.lua | 11 ++++++++--- lua/lualine/components/tabs/tab.lua | 3 ++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lua/lualine/components/tabs/init.lua b/lua/lualine/components/tabs/init.lua index 6c21716..2671e16 100644 --- a/lua/lualine/components/tabs/init.lua +++ b/lua/lualine/components/tabs/init.lua @@ -57,8 +57,8 @@ end function M:update_status() local data = {} local tabs = {} - for t = 1, vim.fn.tabpagenr('$') do - tabs[#tabs + 1] = Tab { tabnr = t, options = self.options, highlights = self.highlights } + for nr, id in ipairs(vim.api.nvim_list_tabpages()) do + tabs[#tabs + 1] = Tab { tabId = id, tabnr = nr, options = self.options, highlights = self.highlights } end -- mark the first, last, current, before current, after current tabpages -- for rendering @@ -93,7 +93,12 @@ function M:update_status() -- start drawing from current tab and draw left and right of it until -- all tabpages are drawn or max_length has been reached. if current_tab == nil then -- maybe redundent code - local t = Tab { tabnr = vim.fn.tabpagenr(), options = self.options, highlights = self.highlights } + local t = Tab { + tabId = vim.api.nvim_get_current_tabpage(), + tabnr = vim.fn.tabpagenr(), + options = self.options, + highlights = self.highlights, + } t.current = true t.last = true data[#data + 1] = t:render() diff --git a/lua/lualine/components/tabs/tab.lua b/lua/lualine/components/tabs/tab.lua index 350aeb2..e7c9e07 100644 --- a/lua/lualine/components/tabs/tab.lua +++ b/lua/lualine/components/tabs/tab.lua @@ -6,6 +6,7 @@ local Tab = require('lualine.utils.class'):extend() function Tab:init(opts) assert(opts.tabnr, 'Cannot create Tab without tabnr') self.tabnr = opts.tabnr + self.tabId = opts.tabId self.options = opts.options self.highlights = opts.highlights end @@ -14,7 +15,7 @@ end --- of the tab. ---@return string function Tab:label() - local custom_tabname = vim.t[self.tabnr].tabname + local custom_tabname = vim.t[self.tabId].tabname if custom_tabname and custom_tabname ~= '' then return custom_tabname end