Skip to content

Commit

Permalink
Use vim.diagnostic.count instead of get (Feat #1239) (#1268)
Browse files Browse the repository at this point in the history
  • Loading branch information
omeyenburg authored Jul 8, 2024
1 parent a023242 commit 6a40b53
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lua/lualine/components/diagnostics/sources.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,19 @@ M.sources = {
workspace_diag(diag_severity.HINT)
end,
nvim_diagnostic = function()
local count

if vim.diagnostic.count ~= nil then -- neovim >= 0.10.0
count = vim.diagnostic.count(0)
return count[vim.diagnostic.severity.ERROR] or 0,
count[vim.diagnostic.severity.WARN] or 0,
count[vim.diagnostic.severity.INFO] or 0,
count[vim.diagnostic.severity.HINT] or 0
end

-- fallback
local diagnostics = vim.diagnostic.get(0)
local count = { 0, 0, 0, 0 }
count = { 0, 0, 0, 0 }
for _, diagnostic in ipairs(diagnostics) do
count[diagnostic.severity] = count[diagnostic.severity] + 1
end
Expand Down

0 comments on commit 6a40b53

Please sign in to comment.