Skip to content

Commit

Permalink
enhance: undeprecate nvim_lsp and completely remove nvim diagnostic…
Browse files Browse the repository at this point in the history
…s 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.
  • Loading branch information
shadmansaleh committed Jan 12, 2022
1 parent 750a94b commit 70691ae
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 46 deletions.
2 changes: 2 additions & 0 deletions BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ☝️
49 changes: 7 additions & 42 deletions lua/lualine/components/diagnostics/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
27 changes: 23 additions & 4 deletions lua/lualine/components/diagnostics/sources.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 70691ae

Please sign in to comment.