diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md index e58412d..856397b 100644 --- a/BREAKING_CHANGES.md +++ b/BREAKING_CHANGES.md @@ -95,3 +95,5 @@ These were hard to understand before. Now the name should convey more info. - luae -> lua_expr - vimf -> vim_fun +### 'nvim' diagnostic soirce has been renamed to 'nvim_diagnostic' +What the title says ☝️ diff --git a/lua/lualine/components/diagnostics/init.lua b/lua/lualine/components/diagnostics/init.lua index 7e2d417..0ceeddb 100644 --- a/lua/lualine/components/diagnostics/init.lua +++ b/lua/lualine/components/diagnostics/init.lua @@ -53,51 +53,16 @@ function M:init(options) } end - -- Error out no source - if #self.options.sources < 1 then - print('no sources for diagnostics configured') - return '' - end - if vim.fn.has('nvim-0.6') == 1 then - for i, name in ipairs(self.options.sources) do - if name == 'nvim_lsp' then - self.options.sources[i] = 'nvim_diagnostic' - modules.utils_notices.add_notice([[ -### diagnostics.source -Diagnostics source `nvim_lsp` has been deprecated in favour of `nvim_diagnostic`. -nvim_diagnostic shows diagnostics from neovim's diagnostics api -while nvim_lsp used to only show lsp diagnostics. - -You've something like this your config. -```lua - {'diagnostics', sources = {'nvim_lsp'}} -``` -It needs to be updated to: -```lua - {'diagnostics', sources = {'nvim_diagnostic'}} -``` -]]) - elseif name == 'nvim' then - self.options.sources[i] = 'nvim_diagnostic' - modules.utils_notices.add_notice([[ -### diagnostics.source -Diagnostics source `nvim` has been renamed to `nvim_diagnostic` - -You've something like this your config. -```lua - {'diagnostics', sources = {'nvim'}} -``` -It needs to be updated to: -```lua - {'diagnostics', sources = {'nvim_diagnostic'}} -``` -]]) - end - end - end -- Initialize variable to store last update so we can use it in insert -- mode for no update_in_insert self.last_diagnostics_count = {} + + -- Error out no source + if #self.options.sources < 1 then + modules.utils_notices.add_notice( + '### diagnostics.sources\n\nno sources for diagnostics configured.\nPlease specify which diagnostics source you want lualine to use with `sources` option.\n' + ) + end end function M:update_status() diff --git a/lua/lualine/components/diagnostics/sources.lua b/lua/lualine/components/diagnostics/sources.lua index 3370d09..f4ef71c 100644 --- a/lua/lualine/components/diagnostics/sources.lua +++ b/lua/lualine/components/diagnostics/sources.lua @@ -5,10 +5,29 @@ local M = {} --- info_count:number, hint_count:number M.sources = { nvim_lsp = function() - local error_count = vim.lsp.diagnostic.get_count(0, 'Error') - local warning_count = vim.lsp.diagnostic.get_count(0, 'Warning') - local info_count = vim.lsp.diagnostic.get_count(0, 'Information') - local hint_count = vim.lsp.diagnostic.get_count(0, 'Hint') + local error_count, warning_count, info_count, hint_count + if vim.fn.has('nvim-0.6') == 1 then + -- On nvim 0.6+ use vim.diagnostic to get lsp generated diagnostic count. + local diagnostics = vim.diagnostic.get(0) + local count = { 0, 0, 0, 0 } + for _, diagnostic in ipairs(diagnostics) do + if vim.startswith(vim.diagnostic.get_namespace(diagnostic.namespace).name, 'vim.lsp') then + count[diagnostic.severity] = count[diagnostic.severity] + 1 + end + end + error_count = count[vim.diagnostic.severity.ERROR] + warning_count = count[vim.diagnostic.severity.WARN] + info_count = count[vim.diagnostic.severity.INFO] + hint_count = count[vim.diagnostic.severity.HINT] + else + -- On 0.5 use older vim.lsp.diagnostic module. + -- Maybe we should phase out support for 0.5 though I haven't yet found a solid reason to. + -- Eventually this will be removed when 0.5 is no longer supported. + error_count = vim.lsp.diagnostic.get_count(0, 'Error') + warning_count = vim.lsp.diagnostic.get_count(0, 'Warning') + info_count = vim.lsp.diagnostic.get_count(0, 'Information') + hint_count = vim.lsp.diagnostic.get_count(0, 'Hint') + end return error_count, warning_count, info_count, hint_count end, nvim_diagnostic = function()