diff --git a/runtime/doc/diagnostic.txt b/runtime/doc/diagnostic.txt index fe822aeaf6..4a4b2abc92 100644 --- 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 index 5a78ad0d0a..7e0c4dd31a 100644 --- 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 index 41e85b82f6..ad08a33fc0 100644 --- 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)