From c5cb601a6ac3390c9e872c19a54f7371aa61f542 Mon Sep 17 00:00:00 2001 From: shadmansaleh <13149513+shadmansaleh@users.noreply.github.com> Date: Fri, 17 Sep 2021 18:50:32 +0600 Subject: [PATCH] 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. --- README.md | 2 +- doc/lualine.txt | 2 +- lua/lualine/components/diagnostics.lua | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cbf5222..9dddefb 100644 --- a/README.md +++ b/README.md @@ -366,7 +366,7 @@ sections = { { 'diagnostics', -- 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 -- {error=error_cnt, warn=warn_cnt, info=info_cnt, hint=hint_cnt} sources = {}, diff --git a/doc/lualine.txt b/doc/lualine.txt index e4c1f15..f84fcd5 100644 --- a/doc/lualine.txt +++ b/doc/lualine.txt @@ -349,7 +349,7 @@ Component specific local options ~ { 'diagnostics', -- 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 -- {error=error_cnt, warn=warn_cnt, info=info_cnt, hint=hint_cnt} sources = {}, diff --git a/lua/lualine/components/diagnostics.lua b/lua/lualine/components/diagnostics.lua index 55cb191..6f85b91 100644 --- a/lua/lualine/components/diagnostics.lua +++ b/lua/lualine/components/diagnostics.lua @@ -183,6 +183,17 @@ Diagnostics.diagnostic_sources = { local hint_count = vim.lsp.diagnostic.get_count(0, 'Hint') return error_count, warning_count, info_count, hint_count 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() local data = vim.b.coc_diagnostic_info if data then @@ -199,6 +210,14 @@ Diagnostics.diagnostic_sources = { return 0, 0, 0, 0 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)