Skip to content

Commit

Permalink
fix(diagnostic): resolve buffer number in get() (#16407)
Browse files Browse the repository at this point in the history
  • Loading branch information
gpanders committed Nov 22, 2021
1 parent e02d473 commit fd6df74
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions runtime/lua/vim/diagnostic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ local function get_diagnostics(bufnr, opts, clamp)
end
end
elseif namespace == nil then
bufnr = get_bufnr(bufnr)
for iter_namespace in pairs(diagnostic_cache[bufnr]) do
for _, diagnostic in pairs(diagnostic_cache[bufnr][iter_namespace]) do
add(diagnostic)
Expand All @@ -407,6 +408,7 @@ local function get_diagnostics(bufnr, opts, clamp)
end
end
else
bufnr = get_bufnr(bufnr)
for _, diagnostic in pairs(diagnostic_cache[bufnr][namespace] or {}) do
add(diagnostic)
end
Expand Down
11 changes: 11 additions & 0 deletions test/functional/lua/diagnostic_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ describe('vim.diagnostic', function()
eq('Diagnostic #1', result[1].message)
end)

it('resolves buffer number 0 to the current buffer', function()
eq(2, exec_lua [[
vim.api.nvim_set_current_buf(diagnostic_bufnr)
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, {
make_error('Diagnostic #1', 1, 1, 1, 1),
make_error('Diagnostic #2', 2, 1, 2, 1),
})
return #vim.diagnostic.get(0)
]])
end)

it('saves and count a single error', function()
eq(1, exec_lua [[
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, {
Expand Down

0 comments on commit fd6df74

Please sign in to comment.