feat: add separate hint diagnostic (#241)

* add separate hint diagnostic

* change to lightbulb icon
This commit is contained in:
Tim Bedard 2021-05-25 15:13:43 -05:00 committed by GitHub
parent 0411f1c830
commit 2aaf434094
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 18 deletions

View File

@ -292,12 +292,13 @@ sections = {
-- nvim_lsp, coc, ale, vim_lsp -- nvim_lsp, coc, ale, vim_lsp
sources = nil, sources = nil,
-- displays diagnostics from defined severity -- displays diagnostics from defined severity
sections = {'error', 'warn', 'info'}, sections = {'error', 'warn', 'info', 'hint'},
-- all colors are in format #rrggbb -- all colors are in format #rrggbb
color_error = nil, -- changes diagnostic's error foreground color color_error = nil, -- changes diagnostic's error foreground color
color_warn = nil, -- changes diagnostic's warn foreground color color_warn = nil, -- changes diagnostic's warn foreground color
color_info = nil, -- Changes diagnostic's info foreground color color_info = nil, -- Changes diagnostic's info foreground color
symbols = {error = 'E', warn = 'W', info = 'I'} color_hint = nil, -- Changes diagnostic's hint foreground color
symbols = {error = 'E', warn = 'W', info = 'I', hint = 'H'}
} }
} }
} }

View File

@ -227,12 +227,13 @@ Component specific local options~
-- nvim_lsp, coc, ale, vim_lsp -- nvim_lsp, coc, ale, vim_lsp
sources = nil, sources = nil,
-- displays diagnostics from defined severity -- displays diagnostics from defined severity
sections = {'error', 'warn', 'info'}, sections = {'error', 'warn', 'info', 'hint'},
-- all colors are in format #rrggbb -- all colors are in format #rrggbb
color_error = nil, -- changes diagnostic's error foreground color color_error = nil, -- changes diagnostic's error foreground color
color_warn = nil, -- changes diagnostic's warn foreground color color_warn = nil, -- changes diagnostic's warn foreground color
color_info = nil, -- Changes diagnostic's info foreground color color_info = nil, -- Changes diagnostic's info foreground color
symbols = {error = 'E', warn = 'W', info = 'I'} color_hint = nil, -- Changes diagnostic's hint foreground color
symbols = {error = 'E', warn = 'W', info = 'I', hint = 'H'}
} }
} }
} }

View File

@ -10,6 +10,7 @@ Diagnostics.default_colors = {
error = '#e32636', error = '#e32636',
warn = '#ffdf00', warn = '#ffdf00',
info = '#ffffff', info = '#ffffff',
hint = '#d7afaf',
} }
-- LuaFormatter on -- LuaFormatter on
@ -19,8 +20,9 @@ Diagnostics.new = function(self, options, child)
local default_symbols = new_diagnostics.options.icons_enabled and { local default_symbols = new_diagnostics.options.icons_enabled and {
error = '', -- xf659 error = '', -- xf659
warn = '', -- xf529 warn = '', -- xf529
info = '' -- xf7fc info = '', -- xf7fc
} or {error = 'E:', warn = 'W:', info = 'I:'} hint = '' -- xf838
} or {error = 'E:', warn = 'W:', info = 'I:', hint = 'H:'}
new_diagnostics.symbols = vim.tbl_extend('force', default_symbols, new_diagnostics.symbols = vim.tbl_extend('force', default_symbols,
new_diagnostics.options.symbols or {}) new_diagnostics.options.symbols or {})
if new_diagnostics.options.sources == nil then if new_diagnostics.options.sources == nil then
@ -28,7 +30,7 @@ Diagnostics.new = function(self, options, child)
return '' return ''
end end
if new_diagnostics.options.sections == nil then if new_diagnostics.options.sections == nil then
new_diagnostics.options.sections = {'error', 'warn', 'info'} new_diagnostics.options.sections = {'error', 'warn', 'info', 'hint'}
end end
if new_diagnostics.options.colored == nil then if new_diagnostics.options.colored == nil then
new_diagnostics.options.colored = true new_diagnostics.options.colored = true
@ -52,6 +54,12 @@ Diagnostics.new = function(self, options, child)
utils.extract_highlight_colors('Normal', 'fg') or utils.extract_highlight_colors('Normal', 'fg') or
Diagnostics.default_colors.info Diagnostics.default_colors.info
end end
if not new_diagnostics.options.color_hint then
new_diagnostics.options.color_hint =
utils.extract_highlight_colors('LspDiagnosticsDefaultHint', 'fg') or
utils.extract_highlight_colors('DiffChange', 'fg') or
Diagnostics.default_colors.hint
end
if new_diagnostics.options.colored then if new_diagnostics.options.colored then
new_diagnostics.highlight_groups = { new_diagnostics.highlight_groups = {
@ -63,6 +71,9 @@ Diagnostics.new = function(self, options, child)
new_diagnostics.options), new_diagnostics.options),
info = highlight.create_component_highlight_group( info = highlight.create_component_highlight_group(
{fg = new_diagnostics.options.color_info}, 'diagnostics_info', {fg = new_diagnostics.options.color_info}, 'diagnostics_info',
new_diagnostics.options),
hint = highlight.create_component_highlight_group(
{fg = new_diagnostics.options.color_hint}, 'diagnostics_hint',
new_diagnostics.options) new_diagnostics.options)
} }
end end
@ -71,15 +82,21 @@ Diagnostics.new = function(self, options, child)
end end
Diagnostics.update_status = function(self) Diagnostics.update_status = function(self)
local error_count, warning_count, info_count = 0, 0, 0 local error_count, warning_count, info_count, hint_count = 0, 0, 0, 0
local diagnostic_data = self.get_diagnostics(self.options.sources) local diagnostic_data = self.get_diagnostics(self.options.sources)
for _, data in pairs(diagnostic_data) do for _, data in pairs(diagnostic_data) do
error_count = error_count + data.error error_count = error_count + data.error
warning_count = warning_count + data.warn warning_count = warning_count + data.warn
info_count = info_count + data.info info_count = info_count + data.info
hint_count = hint_count + data.hint
end end
local result = {} local result = {}
local data = {error = error_count, warn = warning_count, info = info_count} local data = {
error = error_count,
warn = warning_count,
info = info_count,
hint = hint_count
}
if self.options.colored then if self.options.colored then
local colors = {} local colors = {}
for name, hl in pairs(self.highlight_groups) do for name, hl in pairs(self.highlight_groups) do
@ -109,24 +126,24 @@ Diagnostics.diagnostic_sources = {
nvim_lsp = function() nvim_lsp = function()
local error_count = vim.lsp.diagnostic.get_count(0, 'Error') local error_count = vim.lsp.diagnostic.get_count(0, 'Error')
local warning_count = vim.lsp.diagnostic.get_count(0, 'Warning') local warning_count = vim.lsp.diagnostic.get_count(0, 'Warning')
local info_count = vim.lsp.diagnostic.get_count(0, 'Information') + local info_count = vim.lsp.diagnostic.get_count(0, 'Information')
vim.lsp.diagnostic.get_count(0, 'Hint') local hint_count = vim.lsp.diagnostic.get_count(0, 'Hint')
return error_count, warning_count, info_count return error_count, warning_count, info_count, hint_count
end, end,
coc = function() coc = function()
local data = vim.b.coc_diagnostic_info local data = vim.b.coc_diagnostic_info
if data then if data then
return data.error, data.warning, data.information return data.error, data.warning, data.information, data.hint
else else
return 0, 0, 0 return 0, 0, 0, 0
end end
end, end,
ale = function() ale = function()
local ok, data = pcall(vim.fn['ale#statusline#Count'], vim.fn.bufnr()) local ok, data = pcall(vim.fn['ale#statusline#Count'], vim.fn.bufnr())
if ok then if ok then
return data.error, data.warning, data.info return data.error + data.style_error, data.warning + data.style_warning, data.info, 0
else else
return 0, 0, 0 return 0, 0, 0, 0
end end
end end
} }
@ -134,12 +151,13 @@ Diagnostics.diagnostic_sources = {
Diagnostics.get_diagnostics = function(sources) Diagnostics.get_diagnostics = function(sources)
local result = {} local result = {}
for index, source in ipairs(sources) do for index, source in ipairs(sources) do
local error_count, warning_count, info_count = local error_count, warning_count, info_count, hint_count =
Diagnostics.diagnostic_sources[source]() Diagnostics.diagnostic_sources[source]()
result[index] = { result[index] = {
error = error_count, error = error_count,
warn = warning_count, warn = warning_count,
info = info_count info = info_count,
hint = hint_count
} }
end end
return result return result