Skip to content

Commit bb5481c

Browse files
committed
fix(diagnostics): limit amount of diagnostics processed
1 parent 655133c commit bb5481c

1 file changed

Lines changed: 27 additions & 7 deletions

File tree

lua/bufferline/diagnostics.lua

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,36 @@ local function diagnostic_is_enabled(d)
7676
end
7777
end
7878

79+
local get_diagnostics_cache = {}
7980
local get_diagnostics = {
8081
nvim_lsp = function()
8182
local results = {}
82-
local diagnostics = vim.diagnostic.get()
83-
for _, d in pairs(diagnostics) do
84-
if diagnostic_is_enabled(d) then
85-
if not results[d.bufnr] then results[d.bufnr] = {} end
86-
table.insert(results[d.bufnr], d)
87-
end
88-
end
83+
local diagnostics_count = vim.diagnostic.count()
84+
diagnostics_count = math.max(
85+
diagnostics_count[vim.diagnostic.severity.ERROR] or 0,
86+
diagnostics_count[vim.diagnostic.severity.WARN] or 0,
87+
diagnostics_count[vim.diagnostic.severity.INFO] or 0,
88+
diagnostics_count[vim.diagnostic.severity.HINT] or 0
89+
)
90+
91+
local diagnostics = {}
92+
if diagnostics_count > 127 then
93+
return get_diagnostics_cache
94+
else
95+
diagnostics = vim.diagnostic.get()
96+
end
97+
98+
-- Limit amount of diagnostics taht gets processed
99+
for _ = 1, math.min(127, #diagnostics) do
100+
-- for _, d in pairs(diagnostics) do
101+
local d = diagnostics[_]
102+
if diagnostic_is_enabled(d) then
103+
if not results[d.bufnr] then results[d.bufnr] = {} end
104+
table.insert(results[d.bufnr], d)
105+
end
106+
end
107+
get_diagnostics_cache = results
108+
print(vim.inspect({ #diagnostics, #results }))
89109
return results
90110
end,
91111

0 commit comments

Comments
 (0)