fix(diagnostic): accept multiple namespace in open_float() (#34073)

This commit is contained in:
Maria José Solano
2025-05-21 10:54:43 -07:00
committed by GitHub
parent 19efabafc5
commit 2e0158650a
3 changed files with 30 additions and 5 deletions

View File

@@ -546,7 +546,8 @@ Lua module: vim.diagnostic *diagnostic-api*
Fields: ~ Fields: ~
• {bufnr}? (`integer`, default: current buffer) Buffer number • {bufnr}? (`integer`, default: current buffer) Buffer number
to show diagnostics from. to show diagnostics from.
• {namespace}? (`integer`) Limit diagnostics to the given namespace • {namespace}? (`integer|integer[]`) Limit diagnostics to the given
namespace(s).
• {scope}? (`'line'|'buffer'|'cursor'|'c'|'l'|'b'`, default: • {scope}? (`'line'|'buffer'|'cursor'|'c'|'l'|'b'`, default:
`line`) Show diagnostics from the whole buffer `line`) Show diagnostics from the whole buffer
(`buffer"`, the current cursor line (`line`), or the (`buffer"`, the current cursor line (`line`), or the

View File

@@ -115,8 +115,8 @@ end
--- (default: current buffer) --- (default: current buffer)
--- @field bufnr? integer --- @field bufnr? integer
--- ---
--- Limit diagnostics to the given namespace --- Limit diagnostics to the given namespace(s).
--- @field namespace? integer --- @field namespace? integer|integer[]
--- ---
--- Show diagnostics from the whole buffer (`buffer"`, the current cursor line --- Show diagnostics from the whole buffer (`buffer"`, the current cursor line
--- (`line`), or the current cursor position (`cursor`). Shorthand versions --- (`line`), or the current cursor position (`cursor`). Shorthand versions

View File

@@ -2997,7 +2997,7 @@ describe('vim.diagnostic', function()
it('allows filtering by namespace', function() it('allows filtering by namespace', function()
eq( eq(
2, { 'Diagnostics:', '1. Syntax error' },
exec_lua(function() exec_lua(function()
local ns_1_diagnostics = { local ns_1_diagnostics = {
_G.make_error('Syntax error', 0, 1, 0, 3), _G.make_error('Syntax error', 0, 1, 0, 3),
@@ -3012,7 +3012,31 @@ describe('vim.diagnostic', function()
vim.diagnostic.open_float(_G.diagnostic_bufnr, { namespace = _G.diagnostic_ns }) vim.diagnostic.open_float(_G.diagnostic_bufnr, { namespace = _G.diagnostic_ns })
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
vim.api.nvim_win_close(winnr, true) vim.api.nvim_win_close(winnr, true)
return #lines return lines
end)
)
end)
it('allows filtering by multiple namespaces', function()
eq(
{ 'Diagnostics:', '1. Syntax error', '2. Some warning' },
exec_lua(function()
local ns_1_diagnostics = {
_G.make_error('Syntax error', 0, 1, 0, 3),
}
local ns_2_diagnostics = {
_G.make_warning('Some warning', 0, 1, 0, 3),
}
vim.api.nvim_win_set_buf(0, _G.diagnostic_bufnr)
vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, ns_1_diagnostics)
vim.diagnostic.set(_G.other_ns, _G.diagnostic_bufnr, ns_2_diagnostics)
local float_bufnr, winnr = vim.diagnostic.open_float(
_G.diagnostic_bufnr,
{ namespace = { _G.diagnostic_ns, _G.other_ns } }
)
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
vim.api.nvim_win_close(winnr, true)
return lines
end) end)
) )
end) end)