From f60bec0969a729e85d3e0d1d79650328ff8b8698 Mon Sep 17 00:00:00 2001 From: shadmansaleh Date: Sun, 25 Jul 2021 13:48:50 +0600 Subject: [PATCH] feat: Add update_in_insert option to diagnostics component --- README.md | 1 + doc/lualine.txt | 1 + lua/lualine/components/diagnostics.lua | 14 +++++++++++--- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 781c255..6b98d1f 100644 --- a/README.md +++ b/README.md @@ -305,6 +305,7 @@ sections = { color_info = nil, -- Changes diagnostic's info foreground color color_hint = nil, -- Changes diagnostic's hint foreground color symbols = {error = 'E', warn = 'W', info = 'I', hint = 'H'} + update_in_insert = false, -- Update diagnostics in insert mode } } } diff --git a/doc/lualine.txt b/doc/lualine.txt index 4834fd4..b390ca0 100644 --- a/doc/lualine.txt +++ b/doc/lualine.txt @@ -240,6 +240,7 @@ Component specific local options~ color_info = nil, -- Changes diagnostic's info foreground color color_hint = nil, -- Changes diagnostic's hint foreground color symbols = {error = 'E', warn = 'W', info = 'I', hint = 'H'} + update_in_insert = false, -- Update diagnostics in insert mode } } } diff --git a/lua/lualine/components/diagnostics.lua b/lua/lualine/components/diagnostics.lua index 104fe45..ff92aae 100644 --- a/lua/lualine/components/diagnostics.lua +++ b/lua/lualine/components/diagnostics.lua @@ -35,6 +35,10 @@ Diagnostics.new = function(self, options, child) if new_diagnostics.options.colored == nil then new_diagnostics.options.colored = true end + if new_diagnostics.options.update_in_insert == nil then + new_diagnostics.options.update_in_insert = false + end + new_diagnostics.last_update = '' -- apply colors if not new_diagnostics.options.color_error then new_diagnostics.options.color_error = @@ -82,6 +86,10 @@ Diagnostics.new = function(self, options, child) end 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 diagnostic_data = self.get_diagnostics(self.options.sources) for _, data in pairs(diagnostic_data) do @@ -115,11 +123,11 @@ Diagnostics.update_status = function(self) end end end + self.last_update = '' if result[1] ~= nil then - return table.concat(result, ' ') - else - return '' + self.last_update = table.concat(result, ' ') end + return self.last_update end Diagnostics.diagnostic_sources = {