enhance: undeprecate nvim_lsp and completely remove `nvim` diagnostics source 😉

- 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.
This commit is contained in:
shadmansaleh 2022-01-12 22:13:02 +06:00
parent 750a94baef
commit 70691ae350
3 changed files with 32 additions and 46 deletions

View File

@ -95,3 +95,5 @@ These were hard to understand before. Now the name should convey more info.
- luae -> lua_expr - luae -> lua_expr
- vimf -> vim_fun - vimf -> vim_fun
### 'nvim' diagnostic soirce has been renamed to 'nvim_diagnostic'
What the title says ☝️

View File

@ -53,51 +53,16 @@ function M:init(options)
} }
end 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 -- Initialize variable to store last update so we can use it in insert
-- mode for no update_in_insert -- mode for no update_in_insert
self.last_diagnostics_count = {} 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 end
function M:update_status() function M:update_status()

View File

@ -5,10 +5,29 @@ local M = {}
--- info_count:number, hint_count:number --- info_count:number, hint_count:number
M.sources = { M.sources = {
nvim_lsp = function() nvim_lsp = function()
local error_count = vim.lsp.diagnostic.get_count(0, 'Error') local error_count, warning_count, info_count, hint_count
local warning_count = vim.lsp.diagnostic.get_count(0, 'Warning') if vim.fn.has('nvim-0.6') == 1 then
local info_count = vim.lsp.diagnostic.get_count(0, 'Information') -- On nvim 0.6+ use vim.diagnostic to get lsp generated diagnostic count.
local hint_count = vim.lsp.diagnostic.get_count(0, 'Hint') 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 return error_count, warning_count, info_count, hint_count
end, end,
nvim_diagnostic = function() nvim_diagnostic = function()