Skip to content

Commit 08f1e69

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

1 file changed

Lines changed: 26 additions & 5 deletions

File tree

lua/bufferline/diagnostics.lua

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,32 @@ end
7979
local get_diagnostics = {
8080
nvim_lsp = function()
8181
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)
82+
83+
-- skip buffers opened by LSP, use only loaded ones
84+
local current_buffers = vim.api.nvim_list_bufs()
85+
local loaded_buffers = {}
86+
for _, bufnr in ipairs(current_buffers) do
87+
if vim.api.nvim_buf_is_loaded(bufnr) then table.insert(loaded_buffers, bufnr) end
88+
end
89+
90+
for _, bufnr in pairs(loaded_buffers) do
91+
local diagnostics_count = vim.diagnostic.count(bufnr)
92+
diagnostics_count = 0
93+
+ (diagnostics_count[vim.diagnostic.severity.ERROR] or 0)
94+
+ (diagnostics_count[vim.diagnostic.severity.WARN] or 0)
95+
+ (diagnostics_count[vim.diagnostic.severity.INFO] or 0)
96+
+ (diagnostics_count[vim.diagnostic.severity.HINT] or 0)
97+
98+
-- A safeguard to skip processing too many diagnostics altogether per given buffer
99+
if diagnostics_count < 1024 then
100+
local diagnostics = vim.diagnostic.get(bufnr)
101+
for _ = 1, #diagnostics do
102+
local d = diagnostics[_]
103+
if diagnostic_is_enabled(d) then
104+
if not results[d.bufnr] then results[d.bufnr] = {} end
105+
table.insert(results[bufnr], d)
106+
end
107+
end
87108
end
88109
end
89110
return results

0 commit comments

Comments
 (0)