From e909cc3cafc99bdd2793e6be615eb6971b21efc1 Mon Sep 17 00:00:00 2001 From: Mat Jones Date: Thu, 21 Oct 2021 07:55:35 -0400 Subject: [PATCH] feat: add option to always show diagnostics * rename option and add to default config * combine separate if statements using else if --- README.md | 1 + doc/lualine.txt | 1 + lua/lualine/components/diagnostics/config.lua | 1 + lua/lualine/components/diagnostics/init.lua | 12 ++++++++++-- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d2ebb98..ff575da 100644 --- a/README.md +++ b/README.md @@ -460,6 +460,7 @@ sections = { } symbols = {error = 'E', warn = 'W', info = 'I', hint = 'H'} update_in_insert = false, -- Update diagnostics in insert mode + always_visible = false, -- Show diagnostics even if count is 0, boolean or function returning boolean } } } diff --git a/doc/lualine.txt b/doc/lualine.txt index 5d29a15..bc2aae6 100644 --- a/doc/lualine.txt +++ b/doc/lualine.txt @@ -440,6 +440,7 @@ will be. } symbols = {error = 'E', warn = 'W', info = 'I', hint = 'H'} update_in_insert = false, -- Update diagnostics in insert mode + always_visible = false, -- Show diagnostics even if count is 0, boolean or function returning boolean } } } diff --git a/lua/lualine/components/diagnostics/config.lua b/lua/lualine/components/diagnostics/config.lua index dfaab80..5eaf1fe 100644 --- a/lua/lualine/components/diagnostics/config.lua +++ b/lua/lualine/components/diagnostics/config.lua @@ -17,6 +17,7 @@ M.symbols = { M.options = { colored = true, update_in_insert = false, + always_visible = false, sources = { 'nvim_lsp', 'coc' }, sections = { 'error', 'warn', 'info', 'hint' }, diagnostics_color = { diff --git a/lua/lualine/components/diagnostics/init.lua b/lua/lualine/components/diagnostics/init.lua index 7ef416f..f0700db 100644 --- a/lua/lualine/components/diagnostics/init.lua +++ b/lua/lualine/components/diagnostics/init.lua @@ -83,6 +83,14 @@ function M:update_status() info = info_count, hint = hint_count, } + + local always_visible = false + if type(self.options.always_visible) == 'boolean' then + always_visible = self.options.always_visible + elseif type(self.options.always_visible) == 'function' then + always_visible = self.options.always_visible() + end + -- format the counts with symbols and highlights if self.options.colored then local colors = {} @@ -90,13 +98,13 @@ function M:update_status() colors[name] = modules.highlight.component_format_highlight(hl) end for _, section in ipairs(self.options.sections) do - if data[section] ~= nil and data[section] > 0 then + if data[section] ~= nil and (always_visible or data[section] > 0) then table.insert(result, colors[section] .. self.symbols[section] .. data[section]) end end else for _, section in ipairs(self.options.sections) do - if data[section] ~= nil and data[section] > 0 then + if data[section] ~= nil and (always_visible or data[section] > 0) then table.insert(result, self.symbols[section] .. data[section]) end end