feat(diagnostics): Add support for nvims diagnostic API

- neovim added new diagnostics api in https://github.com/neovim/neovim/pull/15585.
  So I've added a new diagnostics source named `nvim` (Yes I couldn't
  find a name for it :P) that shows diagnostics from that api.
  In neovim nightly with vim.diagnostics you can consider source
  `nvim_lsp` obsolete.
- Diagnostics source `vim_lsp` was removed in a mistake now it's
  restored.
This commit is contained in:
shadmansaleh 2021-09-17 18:50:32 +06:00
parent f7702d8841
commit c5cb601a6a
3 changed files with 21 additions and 2 deletions

View File

@ -366,7 +366,7 @@ sections = {
{ {
'diagnostics', 'diagnostics',
-- table of diagnostic sources, available sources: -- table of diagnostic sources, available sources:
-- 'nvim_lsp', 'coc', 'ale', 'vim_lsp' -- 'nvim_lsp', 'nvim', 'coc', 'ale', 'vim_lsp'
-- Or a function that returns a table like -- Or a function that returns a table like
-- {error=error_cnt, warn=warn_cnt, info=info_cnt, hint=hint_cnt} -- {error=error_cnt, warn=warn_cnt, info=info_cnt, hint=hint_cnt}
sources = {}, sources = {},

View File

@ -349,7 +349,7 @@ Component specific local options ~
{ {
'diagnostics', 'diagnostics',
-- table of diagnostic sources, available sources: -- table of diagnostic sources, available sources:
-- 'nvim_lsp', 'coc', 'ale', 'vim_lsp' -- 'nvim_lsp', 'nvim', 'coc', 'ale', 'vim_lsp'
-- Or a function that returns a table like -- Or a function that returns a table like
-- {error=error_cnt, warn=warn_cnt, info=info_cnt, hint=hint_cnt} -- {error=error_cnt, warn=warn_cnt, info=info_cnt, hint=hint_cnt}
sources = {}, sources = {},

View File

@ -183,6 +183,17 @@ Diagnostics.diagnostic_sources = {
local hint_count = vim.lsp.diagnostic.get_count(0, 'Hint') local hint_count = vim.lsp.diagnostic.get_count(0, 'Hint')
return error_count, warning_count, info_count, hint_count return error_count, warning_count, info_count, hint_count
end, end,
nvim = function()
local diagnostics = vim.diagnostic.get(0)
local count = { 0, 0, 0, 0 }
for _, diagnostic in ipairs(diagnostics) do
count[diagnostic.severity] = count[diagnostic.severity] + 1
end
return count[vim.diagnostic.severity.ERROR],
count[vim.diagnostic.severity.WARN],
count[vim.diagnostic.severity.INFO],
count[vim.diagnostic.severity.HINT]
end,
coc = function() coc = function()
local data = vim.b.coc_diagnostic_info local data = vim.b.coc_diagnostic_info
if data then if data then
@ -199,6 +210,14 @@ Diagnostics.diagnostic_sources = {
return 0, 0, 0, 0 return 0, 0, 0, 0
end end
end, end,
vim_lsp = function()
local ok, data = pcall(vim.fn['lsp#get_buffer_diagnostics_counts'])
if ok then
return data.error, data.warning, data.information
else
return 0, 0, 0
end
end,
} }
Diagnostics.get_diagnostics = function(sources) Diagnostics.get_diagnostics = function(sources)