Merge pull request #1 from shadmansaleh/feat/diagnostic/add_option/update_in_insert

feat: Add update_in_insert option to diagnostics component
This commit is contained in:
Shadman 2021-07-25 13:51:37 +06:00 committed by GitHub
commit ab818ec91a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 3 deletions

View File

@ -305,6 +305,7 @@ sections = {
color_info = nil, -- Changes diagnostic's info foreground color color_info = nil, -- Changes diagnostic's info foreground color
color_hint = nil, -- Changes diagnostic's hint foreground color color_hint = nil, -- Changes diagnostic's hint foreground color
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
} }
} }
} }

View File

@ -240,6 +240,7 @@ Component specific local options~
color_info = nil, -- Changes diagnostic's info foreground color color_info = nil, -- Changes diagnostic's info foreground color
color_hint = nil, -- Changes diagnostic's hint foreground color color_hint = nil, -- Changes diagnostic's hint foreground color
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
} }
} }
} }

View File

@ -35,6 +35,10 @@ Diagnostics.new = function(self, options, child)
if new_diagnostics.options.colored == nil then if new_diagnostics.options.colored == nil then
new_diagnostics.options.colored = true new_diagnostics.options.colored = true
end end
if new_diagnostics.options.update_in_insert == nil then
new_diagnostics.options.update_in_insert = false
end
new_diagnostics.last_update = ''
-- apply colors -- apply colors
if not new_diagnostics.options.color_error then if not new_diagnostics.options.color_error then
new_diagnostics.options.color_error = new_diagnostics.options.color_error =
@ -82,6 +86,10 @@ Diagnostics.new = function(self, options, child)
end end
Diagnostics.update_status = function(self) Diagnostics.update_status = function(self)
if not self.options.update_in_insert
and vim.api.nvim_get_mode().mode:sub(1,1) == 'i' then
return self.last_update
end
local error_count, warning_count, info_count, hint_count = 0, 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
@ -115,11 +123,11 @@ Diagnostics.update_status = function(self)
end end
end end
end end
self.last_update = ''
if result[1] ~= nil then if result[1] ~= nil then
return table.concat(result, ' ') self.last_update = table.concat(result, ' ')
else
return ''
end end
return self.last_update
end end
Diagnostics.diagnostic_sources = { Diagnostics.diagnostic_sources = {