feat: add option to always show diagnostics

* rename option and add to default config

* combine separate if statements using else if
This commit is contained in:
Mat Jones 2021-10-21 07:55:35 -04:00 committed by shadmansaleh
parent ad4f4ff751
commit e909cc3caf
4 changed files with 13 additions and 2 deletions

View File

@ -460,6 +460,7 @@ sections = {
} }
symbols = {error = 'E', warn = 'W', info = 'I', hint = 'H'} symbols = {error = 'E', warn = 'W', info = 'I', hint = 'H'}
update_in_insert = false, -- Update diagnostics in insert mode update_in_insert = false, -- Update diagnostics in insert mode
always_visible = false, -- Show diagnostics even if count is 0, boolean or function returning boolean
} }
} }
} }

View File

@ -440,6 +440,7 @@ will be.
} }
symbols = {error = 'E', warn = 'W', info = 'I', hint = 'H'} symbols = {error = 'E', warn = 'W', info = 'I', hint = 'H'}
update_in_insert = false, -- Update diagnostics in insert mode update_in_insert = false, -- Update diagnostics in insert mode
always_visible = false, -- Show diagnostics even if count is 0, boolean or function returning boolean
} }
} }
} }

View File

@ -17,6 +17,7 @@ M.symbols = {
M.options = { M.options = {
colored = true, colored = true,
update_in_insert = false, update_in_insert = false,
always_visible = false,
sources = { 'nvim_lsp', 'coc' }, sources = { 'nvim_lsp', 'coc' },
sections = { 'error', 'warn', 'info', 'hint' }, sections = { 'error', 'warn', 'info', 'hint' },
diagnostics_color = { diagnostics_color = {

View File

@ -83,6 +83,14 @@ function M:update_status()
info = info_count, info = info_count,
hint = hint_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 -- format the counts with symbols and highlights
if self.options.colored then if self.options.colored then
local colors = {} local colors = {}
@ -90,13 +98,13 @@ function M:update_status()
colors[name] = modules.highlight.component_format_highlight(hl) colors[name] = modules.highlight.component_format_highlight(hl)
end end
for _, section in ipairs(self.options.sections) do 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]) table.insert(result, colors[section] .. self.symbols[section] .. data[section])
end end
end end
else else
for _, section in ipairs(self.options.sections) do 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]) table.insert(result, self.symbols[section] .. data[section])
end end
end end