Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions lua/bufferline/diagnostics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,32 @@ end
local get_diagnostics = {
nvim_lsp = function()
local results = {}
local diagnostics = vim.diagnostic.get()
for _, d in pairs(diagnostics) do
if diagnostic_is_enabled(d) then
if not results[d.bufnr] then results[d.bufnr] = {} end
table.insert(results[d.bufnr], d)

-- skip buffers opened by LSP, use only loaded ones
local current_buffers = vim.api.nvim_list_bufs()
local loaded_buffers = {}
for _, bufnr in ipairs(current_buffers) do
if vim.api.nvim_buf_is_loaded(bufnr) then table.insert(loaded_buffers, bufnr) end
end

for _, bufnr in pairs(loaded_buffers) do
local diagnostics_count = vim.diagnostic.count(bufnr)
diagnostics_count = 0
+ (diagnostics_count[vim.diagnostic.severity.ERROR] or 0)
+ (diagnostics_count[vim.diagnostic.severity.WARN] or 0)
+ (diagnostics_count[vim.diagnostic.severity.INFO] or 0)
+ (diagnostics_count[vim.diagnostic.severity.HINT] or 0)

-- A safeguard to skip processing too many diagnostics altogether per given buffer
if diagnostics_count < 1024 then
local diagnostics = vim.diagnostic.get(bufnr)
for _ = 1, #diagnostics do
local d = diagnostics[_]
if diagnostic_is_enabled(d) then
if not results[d.bufnr] then results[d.bufnr] = {} end
table.insert(results[bufnr], d)
end
end
end
end
return results
Expand Down