Skip to content

Commit 694e0a7

Browse files
committed
perf(status): use vim.diagnostic.count if available
1 parent 716b2f6 commit 694e0a7

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lua/astroui/status/condition.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,12 @@ end
122122
function M.has_diagnostics(bufnr)
123123
if type(bufnr) == "table" then bufnr = bufnr.bufnr end
124124
if package.loaded["astrolsp"] and require("astrolsp").config.features.diagnostics_mode == 0 then return false end
125-
return #vim.diagnostic.get(bufnr or 0) > 0
125+
-- TODO: remove when dropping support for neovim 0.9
126+
if vim.diagnostic.count then
127+
return vim.tbl_contains(vim.diagnostic.count(bufnr or 0), function(v) return v > 0 end, { predicate = true })
128+
else
129+
return #vim.diagnostic.get(bufnr or 0) > 0
130+
end
126131
end
127132

128133
--- A condition function if there is a defined filetype

lua/astroui/status/provider.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,13 @@ function M.diagnostics(opts)
452452
if not opts or not opts.severity then return end
453453
return function(self)
454454
local bufnr = self and self.bufnr or 0
455-
local count = #vim.diagnostic.get(bufnr, opts.severity and { severity = vim.diagnostic.severity[opts.severity] })
455+
local count
456+
-- TODO: remove when dropping support for neovim 0.9
457+
if vim.diagnostic.count then
458+
count = vim.diagnostic.count(bufnr)[vim.diagnostic.severity[opts.severity]] or 0
459+
else
460+
count = #vim.diagnostic.get(bufnr, opts.severity and { severity = vim.diagnostic.severity[opts.severity] })
461+
end
456462
return status_utils.stylize(count ~= 0 and tostring(count) or "", opts)
457463
end
458464
end

0 commit comments

Comments
 (0)