From 70691ae350fdbe1f15758e3b8e2973742a7967a9 Mon Sep 17 00:00:00 2001 From: shadmansaleh <13149513+shadmansaleh@users.noreply.github.com> Date: Wed, 12 Jan 2022 22:13:02 +0600 Subject: [PATCH] =?UTF-8?q?enhance:=20undeprecate=20nvim=5Flsp=20and=20com?= =?UTF-8?q?pletely=20remove=20`nvim`=20diagnostics=20source=20=F0=9F=98=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Now `nvim_lsp` source shows diagnostics generated by vim.lsp only avoids uses vim.diagnostic to avoid deprecation warning on nvim 0.6+ Why? `vim.lsp.diagnostic` deprecation warnings are way too aggressive. And I'm annoyed by people complaining here even though the warning is generated by some other plugin (After introduction of nvim_diagnostic source lualine just can't produce that warning it used to switch users to nvim_diagnostic source with a warning on nvim0.6+). Forget it just let anyone that wants lsp specific diagnostics have `nvim_lsp` . I'd still recommend using `nvim_diagnostic` over `nvim_lsp` as diagnostics generayed by plugins like `null-ls` won't showup in `nvim_lsp` - Remove remanents of `nvim` diagnostics source. --- BREAKING_CHANGES.md | 2 + lua/lualine/components/diagnostics/init.lua | 49 +++---------------- .../components/diagnostics/sources.lua | 27 ++++++++-- 3 files changed, 32 insertions(+), 46 deletions(-) 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()