From f6448412065e5678579db36e3c4e60807bf46a84 Mon Sep 17 00:00:00 2001 From: Hubert Pelczarski <41551030+hoob3rt@users.noreply.github.com> Date: Tue, 11 May 2021 21:40:54 +0200 Subject: [PATCH] fix: extensions not loading properly (#232) * refactor: removed inactive sections from extensions * fix: extensions not loading properly --- lua/lualine/extensions/chadtree.lua | 2 -- lua/lualine/extensions/fugitive.lua | 2 -- lua/lualine/extensions/fzf.lua | 2 -- lua/lualine/extensions/nerdtree.lua | 2 -- lua/lualine/extensions/nvim-tree.lua | 4 +--- lua/lualine/extensions/quickfix.lua | 2 -- lua/lualine/init.lua | 29 +++++++++++++--------------- lua/lualine/utils/loader.lua | 1 - 8 files changed, 14 insertions(+), 30 deletions(-) diff --git a/lua/lualine/extensions/chadtree.lua b/lua/lualine/extensions/chadtree.lua index 992f5fb..7033b11 100644 --- a/lua/lualine/extensions/chadtree.lua +++ b/lua/lualine/extensions/chadtree.lua @@ -6,8 +6,6 @@ local M = {} M.sections = vim.deepcopy(nerdtree.sections) -M.inactive_sections = vim.deepcopy(nerdtree.inactive_sections) - M.filetypes = {'CHADTree'} return M diff --git a/lua/lualine/extensions/fugitive.lua b/lua/lualine/extensions/fugitive.lua index bd7d7b1..acbb24d 100644 --- a/lua/lualine/extensions/fugitive.lua +++ b/lua/lualine/extensions/fugitive.lua @@ -9,8 +9,6 @@ end M.sections = {lualine_a = {fugitive_branch}, lualine_z = {'location'}} -M.inactive_sections = vim.deepcopy(M.sections) - M.filetypes = {'fugitive'} return M diff --git a/lua/lualine/extensions/fzf.lua b/lua/lualine/extensions/fzf.lua index 72f38ce..bb3ec7c 100644 --- a/lua/lualine/extensions/fzf.lua +++ b/lua/lualine/extensions/fzf.lua @@ -6,8 +6,6 @@ local M = {} M.sections = {lualine_a = {fzf_statusline}} -M.inactive_sections = vim.deepcopy(M.sections) - M.filetypes = {'fzf'} return M diff --git a/lua/lualine/extensions/nerdtree.lua b/lua/lualine/extensions/nerdtree.lua index 43a4ca9..53b1fcd 100644 --- a/lua/lualine/extensions/nerdtree.lua +++ b/lua/lualine/extensions/nerdtree.lua @@ -6,8 +6,6 @@ local M = {} M.sections = {lualine_a = {get_short_cwd}} -M.inactive_sections = vim.deepcopy(M.sections) - M.filetypes = {'nerdtree'} return M diff --git a/lua/lualine/extensions/nvim-tree.lua b/lua/lualine/extensions/nvim-tree.lua index aef405c..19731c4 100644 --- a/lua/lualine/extensions/nvim-tree.lua +++ b/lua/lualine/extensions/nvim-tree.lua @@ -4,9 +4,7 @@ local nerdtree = require('lualine.extensions.nerdtree') local M = {} -M.sections = vim.deepcopy(nerdtree.inactive_sections) - -M.inactive_sections = vim.deepcopy(nerdtree.inactive_sections) +M.sections = vim.deepcopy(nerdtree.sections) M.filetypes = {'NvimTree'} diff --git a/lua/lualine/extensions/quickfix.lua b/lua/lualine/extensions/quickfix.lua index c9af169..8df915e 100644 --- a/lua/lualine/extensions/quickfix.lua +++ b/lua/lualine/extensions/quickfix.lua @@ -12,8 +12,6 @@ M.sections = { lualine_z = {'location'} } -M.inactive_sections = vim.deepcopy(M.sections) - M.filetypes = {'qf'} return M diff --git a/lua/lualine/init.lua b/lua/lualine/init.lua index 1058cb2..e696966 100644 --- a/lua/lualine/init.lua +++ b/lua/lualine/init.lua @@ -91,17 +91,14 @@ end -- check if any extension matches the filetype and return proper sections local function get_extension_sections() - local sections, inactive_sections = nil, nil for _, extension in ipairs(config.extensions) do for _, filetype in ipairs(extension.filetypes) do - if vim.bo.filetype == filetype then - sections = extension.sections - inactive_sections = extension.inactive_sections - break - end + local current_ft = vim.api.nvim_buf_get_option( + vim.fn.winbufnr(vim.g.statusline_winid), 'filetype') + if current_ft == filetype then return extension.sections end end end - return {sections = sections, inactive_sections = inactive_sections} + return nil end local function status_dispatch() @@ -116,15 +113,15 @@ local function status_dispatch() end local extension_sections = get_extension_sections() if vim.g.statusline_winid == vim.fn.win_getid() then - local sections = extension_sections.sections - if sections == nil then sections = config.sections end - return statusline(sections, true) - else - local inactive_sections = extension_sections.inactive_sections - if inactive_sections == nil then - inactive_sections = config.inactive_sections + if extension_sections ~= nil then + return statusline(extension_sections, true) end - return statusline(inactive_sections, false) + return statusline(config.sections, true) + else + if extension_sections ~= nil then + return statusline(extension_sections, false) + end + return statusline(config.inactive_sections, false) end end @@ -173,7 +170,7 @@ local function set_statusline() augroup lualine autocmd! autocmd WinLeave,BufLeave * lua vim.wo.statusline=require'lualine'.statusline() - autocmd WinEnter,BufEnter * set statusline< + autocmd BufWinEnter,WinEnter,BufEnter * set statusline< autocmd VimResized * redrawstatus augroup END ]], false) diff --git a/lua/lualine/utils/loader.lua b/lua/lualine/utils/loader.lua index 69b4ebb..066a652 100644 --- a/lua/lualine/utils/loader.lua +++ b/lua/lualine/utils/loader.lua @@ -54,7 +54,6 @@ local function load_extensions(config) for index, extension in pairs(config.extensions) do local local_extension = require('lualine.extensions.' .. extension) load_sections(local_extension.sections, config.options) - load_sections(local_extension.inactive_sections, config.options) config.extensions[index] = local_extension end end