Skip to content

Commit 1f0595e

Browse files
committed
Modify LintProc:publish method
The method now uses the value of 'vim.Diagnostic.bufnr', if it is set, instead of always using 'self.bufnr'.
1 parent 9da1fb9 commit 1f0595e

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

lua/lint.lua

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,32 @@ local linter_proc_mt = {
231231
}
232232

233233

234+
---@param diagnostics vim.Diagnostic[]
234235
function LintProc:publish(diagnostics)
235-
-- By the time the linter is finished the user might have deleted the buffer
236-
if api.nvim_buf_is_valid(self.bufnr) and not self.cancelled then
237-
vim.diagnostic.set(self.ns, self.bufnr, diagnostics)
236+
if not self.cancelled then
237+
-- A map where the key is the bufnr and the value is a list of all diagnostics
238+
-- in that buffer.
239+
---@type table<integer,vim.Diagnostic[]>
240+
local buffer_diagnostics = {}
241+
242+
for _, item in ipairs(diagnostics) do
243+
local bufnr = item.bufnr or self.bufnr
244+
245+
if nil == buffer_diagnostics[bufnr] then
246+
buffer_diagnostics[bufnr] = {}
247+
end
248+
249+
table.insert(buffer_diagnostics[bufnr], item)
250+
end
251+
252+
for buf, diags in pairs(buffer_diagnostics) do
253+
-- By the time the linter is finished some buffers may be deleted.
254+
if api.nvim_buf_is_valid(buf) then
255+
vim.diagnostic.set(self.ns, buf, diags)
256+
end
257+
end
238258
end
259+
239260
self.stdout:shutdown()
240261
self.stdout:close()
241262
self.stderr:shutdown()

0 commit comments

Comments
 (0)