Skip to content

Commit 6a40b53

Browse files
authored
Use vim.diagnostic.count instead of get (Feat #1239) (#1268)
1 parent a023242 commit 6a40b53

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lua/lualine/components/diagnostics/sources.lua

+12-1
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,19 @@ M.sources = {
3333
workspace_diag(diag_severity.HINT)
3434
end,
3535
nvim_diagnostic = function()
36+
local count
37+
38+
if vim.diagnostic.count ~= nil then -- neovim >= 0.10.0
39+
count = vim.diagnostic.count(0)
40+
return count[vim.diagnostic.severity.ERROR] or 0,
41+
count[vim.diagnostic.severity.WARN] or 0,
42+
count[vim.diagnostic.severity.INFO] or 0,
43+
count[vim.diagnostic.severity.HINT] or 0
44+
end
45+
46+
-- fallback
3647
local diagnostics = vim.diagnostic.get(0)
37-
local count = { 0, 0, 0, 0 }
48+
count = { 0, 0, 0, 0 }
3849
for _, diagnostic in ipairs(diagnostics) do
3950
count[diagnostic.severity] = count[diagnostic.severity] + 1
4051
end

0 commit comments

Comments
 (0)