From 0521ada344fe2c2b5522c839e5813e19299fc0e7 Mon Sep 17 00:00:00 2001 From: Yohanes Bandung Bondowoso Date: Thu, 28 Jul 2022 01:02:58 +0700 Subject: [PATCH] feat: add workspace diagnostics source (#618) * feat: add workspace diagnostics source * doc: add nvim_workspace_diagnostics to list of sources Co-authored-by: Shadman <13149513+shadmansaleh@users.noreply.github.com> --- README.md | 2 +- doc/lualine.txt | 2 +- lua/lualine/components/diagnostics/sources.lua | 13 +++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1d74045..a762471 100644 --- a/README.md +++ b/README.md @@ -512,7 +512,7 @@ sections = { 'diagnostics', -- Table of diagnostic sources, available sources are: - -- 'nvim_lsp', 'nvim_diagnostic', 'coc', 'ale', 'vim_lsp'. + -- 'nvim_lsp', 'nvim_diagnostic', 'nvim_workspace_diagnostic', 'coc', 'ale', 'vim_lsp'. -- or a function that returns a table as such: -- { error=error_cnt, warn=warn_cnt, info=info_cnt, hint=hint_cnt } sources = { 'nvim_diagnostic', 'coc' }, diff --git a/doc/lualine.txt b/doc/lualine.txt index 8107464..d4db421 100644 --- a/doc/lualine.txt +++ b/doc/lualine.txt @@ -530,7 +530,7 @@ Component specific options These are options that are available on 'diagnostics', -- Table of diagnostic sources, available sources are: - -- 'nvim_lsp', 'nvim_diagnostic', 'coc', 'ale', 'vim_lsp'. + -- 'nvim_lsp', 'nvim_diagnostic', 'nvim_workspace_diagnostic', 'coc', 'ale', 'vim_lsp'. -- or a function that returns a table as such: -- { error=error_cnt, warn=warn_cnt, info=info_cnt, hint=hint_cnt } sources = { 'nvim_diagnostic', 'coc' }, diff --git a/lua/lualine/components/diagnostics/sources.lua b/lua/lualine/components/diagnostics/sources.lua index f4ef71c..22c5587 100644 --- a/lua/lualine/components/diagnostics/sources.lua +++ b/lua/lualine/components/diagnostics/sources.lua @@ -30,6 +30,19 @@ M.sources = { end return error_count, warning_count, info_count, hint_count end, + nvim_workspace_diagnostic = function() + local diag_severity = vim.diagnostic.severity + + local function workspace_diag(severity) + local count = vim.diagnostic.get(nil, {severity = severity}) + return vim.tbl_count(count) + end + + return workspace_diag(diag_severity.ERROR), + workspace_diag(diag_severity.WARN), + workspace_diag(diag_severity.HINT), + workspace_diag(diag_severity.INFO) + end, nvim_diagnostic = function() local diagnostics = vim.diagnostic.get(0) local count = { 0, 0, 0, 0 }