neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 2e0158650a3be0bcfdb6a2f28c6d7266c525e94a
parent 19efabafc56862c4b1f78d147cae702cde59c95d
Author: Maria José Solano <majosolano99@gmail.com>
Date:   Wed, 21 May 2025 10:54:43 -0700

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


Diffstat:
Mruntime/doc/diagnostic.txt | 3++-
Mruntime/lua/vim/diagnostic.lua | 4++--
Mtest/functional/lua/diagnostic_spec.lua | 28++++++++++++++++++++++++++--
3 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/runtime/doc/diagnostic.txt b/runtime/doc/diagnostic.txt @@ -546,7 +546,8 @@ Lua module: vim.diagnostic *diagnostic-api* Fields: ~ • {bufnr}? (`integer`, default: current buffer) Buffer number 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: `line`) Show diagnostics from the whole buffer (`buffer"`, the current cursor line (`line`), or the diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua @@ -115,8 +115,8 @@ end --- (default: current buffer) --- @field bufnr? integer --- ---- Limit diagnostics to the given namespace ---- @field namespace? integer +--- Limit diagnostics to the given namespace(s). +--- @field namespace? integer|integer[] --- --- Show diagnostics from the whole buffer (`buffer"`, the current cursor line --- (`line`), or the current cursor position (`cursor`). Shorthand versions diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua @@ -2997,7 +2997,7 @@ describe('vim.diagnostic', function() it('allows filtering by namespace', function() eq( - 2, + { 'Diagnostics:', '1. Syntax error' }, exec_lua(function() local ns_1_diagnostics = { _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 }) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) 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)