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
This commit is contained in:
shadmansaleh 2021-12-09 23:18:11 +06:00
parent d68631d2c0
commit 4231b63196
7 changed files with 51 additions and 16 deletions

View File

@ -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

View File

@ -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

View File

@ -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 = {

View File

@ -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 = {}

View File

@ -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

View File

@ -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' },

View File

@ -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' },