Skip to content

Commit

Permalink
fix(diagnostics): use main buffer for buffer-local diags
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed May 30, 2024
1 parent 9045e93 commit 259770d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lua/trouble/sources/diagnostics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ function M.setup()
})
for _, diag in ipairs(vim.diagnostic.get()) do
local buf = diag.bufnr
if buf then
if buf and vim.api.nvim_buf_is_valid(buf) then
cache[buf] = cache[buf] or {}
table.insert(cache[buf], M.item(diag))
end
end
end

---@param diag Diagnostic
---@param diag vim.Diagnostic
function M.item(diag)
return Item.new({
source = "diagnostics",
Expand All @@ -97,10 +97,10 @@ end
---@param ctx trouble.Source.ctx)
function M.get(cb, ctx)
-- PERF: pre-filter when possible
local buf = type(ctx.filter) == "table" and ctx.filter.buf or nil
local buf = type(ctx.opts.filter) == "table" and ctx.opts.filter.buf or nil

if buf == 0 then
buf = vim.api.nvim_get_current_buf()
buf = ctx.main.buf
end

if buf then
Expand Down

0 comments on commit 259770d

Please sign in to comment.