From 4231b63196a0dcc94e62e914d2b768ef31b5beb7 Mon Sep 17 00:00:00 2001 From: shadmansaleh <13149513+shadmansaleh@users.noreply.github.com> Date: Thu, 9 Dec 2021 23:18:11 +0600 Subject: [PATCH] fix: lsp.diagnostics deprecation warning - change default diagnostics source from nvim_lsp to nvim_diagnostic and deprecate nvim_lsp on neovim-0.6 and higher. - rename diagnostics source nvim to nvim_diagnostic. nvim could be confusing. fixes #473 --- README.md | 11 +++--- doc/lualine.txt | 11 +++--- lua/lualine/components/diagnostics/config.lua | 2 +- lua/lualine/components/diagnostics/init.lua | 37 +++++++++++++++++++ .../components/diagnostics/sources.lua | 2 +- lua/lualine/config.lua | 2 +- lua/tests/spec/config_spec.lua | 2 +- 7 files changed, 51 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 2464773..f3759f2 100644 --- a/README.md +++ b/README.md @@ -126,8 +126,7 @@ require'lualine'.setup { }, sections = { lualine_a = {'mode'}, - lualine_b = {'branch', 'diff', - {'diagnostics', sources={'nvim_lsp', 'coc'}}}, + lualine_b = {'branch', 'diff', 'diagnostics'}, lualine_c = {'filename'}, lualine_x = {'encoding', 'fileformat', 'filetype'}, lualine_y = {'progress'}, @@ -433,18 +432,18 @@ sections = { { 'diagnostics', -- table of diagnostic sources, available sources: - -- 'nvim_lsp', 'nvim', 'coc', 'ale', 'vim_lsp' + -- 'nvim_lsp', 'nvim_diagnostic', 'coc', 'ale', 'vim_lsp' -- Or a function that returns a table like -- {error=error_cnt, warn=warn_cnt, info=info_cnt, hint=hint_cnt} - sources = {'nvim_lsp', 'coc'}, + sources = {'nvim_diagnostic', 'coc'}, -- displays diagnostics from defined severity sections = {'error', 'warn', 'info', 'hint'}, diagnostics_color = { -- Same values like general color option can be used here. error = 'DiagnosticError', -- changes diagnostic's error color warn = 'DiagnosticWarn', -- changes diagnostic's warn color - info = 'DiagnosticInfo', -- Changes diagnostic's info color - hint = 'DiagnosticHint', -- Changes diagnostic's hint color + info = 'DiagnosticInfo', -- changes diagnostic's info color + hint = 'DiagnosticHint', -- changes diagnostic's hint color }, symbols = {error = 'E', warn = 'W', info = 'I', hint = 'H'}, colored = true, -- displays diagnostics status in color if set to true diff --git a/doc/lualine.txt b/doc/lualine.txt index ddffcd5..f82c101 100644 --- a/doc/lualine.txt +++ b/doc/lualine.txt @@ -113,8 +113,7 @@ checkout `:help lua-heredoc`. }, sections = { lualine_a = {'mode'}, - lualine_b = {'branch', 'diff', - {'diagnostics', sources={'nvim_lsp', 'coc'}}}, + lualine_b = {'branch', 'diff', 'diagnostics'}, lualine_c = {'filename'}, lualine_x = {'encoding', 'fileformat', 'filetype'}, lualine_y = {'progress'}, @@ -457,18 +456,18 @@ Component specific options These are options that are available on { 'diagnostics', -- table of diagnostic sources, available sources: - -- 'nvim_lsp', 'nvim', 'coc', 'ale', 'vim_lsp' + -- 'nvim_lsp', 'nvim_diagnostic', 'coc', 'ale', 'vim_lsp' -- Or a function that returns a table like -- {error=error_cnt, warn=warn_cnt, info=info_cnt, hint=hint_cnt} - sources = {'nvim_lsp', 'coc'}, + sources = {'nvim_diagnostic', 'coc'}, -- displays diagnostics from defined severity sections = {'error', 'warn', 'info', 'hint'}, diagnostics_color = { -- Same values like general color option can be used here. error = 'DiagnosticError', -- changes diagnostic's error color warn = 'DiagnosticWarn', -- changes diagnostic's warn color - info = 'DiagnosticInfo', -- Changes diagnostic's info color - hint = 'DiagnosticHint', -- Changes diagnostic's hint color + info = 'DiagnosticInfo', -- changes diagnostic's info color + hint = 'DiagnosticHint', -- changes diagnostic's hint color }, symbols = {error = 'E', warn = 'W', info = 'I', hint = 'H'}, colored = true, -- displays diagnostics status in color if set to true diff --git a/lua/lualine/components/diagnostics/config.lua b/lua/lualine/components/diagnostics/config.lua index dd97b2d..e491d15 100644 --- a/lua/lualine/components/diagnostics/config.lua +++ b/lua/lualine/components/diagnostics/config.lua @@ -18,7 +18,7 @@ M.options = { colored = true, update_in_insert = false, always_visible = false, - sources = { 'nvim_lsp', 'coc' }, + sources = { vim.fn.has 'nvim-0.6' == 1 and 'nvim_diagnostic' or 'nvim_lsp', 'coc' }, sections = { 'error', 'warn', 'info', 'hint' }, diagnostics_color = { error = { diff --git a/lua/lualine/components/diagnostics/init.lua b/lua/lualine/components/diagnostics/init.lua index 47aea00..85034ae 100644 --- a/lua/lualine/components/diagnostics/init.lua +++ b/lua/lualine/components/diagnostics/init.lua @@ -58,6 +58,43 @@ function M:init(options) print 'no sources for diagnostics configured' return '' end + if vim.fn.has 'nvim-0.6' 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 = {} diff --git a/lua/lualine/components/diagnostics/sources.lua b/lua/lualine/components/diagnostics/sources.lua index 2c621c6..716d20e 100644 --- a/lua/lualine/components/diagnostics/sources.lua +++ b/lua/lualine/components/diagnostics/sources.lua @@ -11,7 +11,7 @@ M.sources = { local hint_count = vim.lsp.diagnostic.get_count(0, 'Hint') return error_count, warning_count, info_count, hint_count end, - nvim = function() + nvim_diagnostic = function() local diagnostics = vim.diagnostic.get(0) local count = { 0, 0, 0, 0 } for _, diagnostic in ipairs(diagnostics) do diff --git a/lua/lualine/config.lua b/lua/lualine/config.lua index 10ead32..9440a96 100644 --- a/lua/lualine/config.lua +++ b/lua/lualine/config.lua @@ -13,7 +13,7 @@ local config = { }, sections = { lualine_a = { 'mode' }, - lualine_b = { 'branch', 'diff', { 'diagnostics', sources = { 'nvim_lsp', 'coc' } } }, + lualine_b = { 'branch', 'diff', 'diagnostics' }, lualine_c = { 'filename' }, lualine_x = { 'encoding', 'fileformat', 'filetype' }, lualine_y = { 'progress' }, diff --git a/lua/tests/spec/config_spec.lua b/lua/tests/spec/config_spec.lua index df5d48c..9e5c50f 100644 --- a/lua/tests/spec/config_spec.lua +++ b/lua/tests/spec/config_spec.lua @@ -115,7 +115,7 @@ describe('config parsing', function() config = config_module.apply_configuration(config) local lualine_default_sections = { lualine_a = { 'mode' }, - lualine_b = { 'branch', 'diff', { 'diagnostics', sources = { 'nvim_lsp', 'coc' } } }, + lualine_b = { 'branch', 'diff', 'diagnostics' }, lualine_c = { 'filename' }, lualine_x = { 'encoding', 'fileformat', 'filetype' }, lualine_y = { 'progress' },