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)