From c681336e3c35bcc39cfe1d5360ac22ec8a6677c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maria=20Jos=C3=A9=20Solano?= Date: Mon, 12 May 2025 19:13:26 -0500 Subject: [PATCH] fix(diagnostic): accept multiple namespaces when setting loclist/qflist (#33982) --- runtime/doc/diagnostic.txt | 8 ++++---- runtime/lua/vim/diagnostic.lua | 8 ++++---- test/functional/lua/diagnostic_spec.lua | 20 ++++++++++++++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/runtime/doc/diagnostic.txt b/runtime/doc/diagnostic.txt index 05129a58e9..26b6f601a6 100644 --- a/runtime/doc/diagnostic.txt +++ b/runtime/doc/diagnostic.txt @@ -913,8 +913,8 @@ setloclist({opts}) *vim.diagnostic.setloclist()* Parameters: ~ • {opts} (`table?`) Configuration table with the following keys: - • {namespace}? (`integer`) Only add diagnostics from the given - namespace. + • {namespace}? (`integer[]|integer`) Only add diagnostics from + the given namespace(s). • {winnr}? (`integer`, default: `0`) Window number to set location list for. • {open}? (`boolean`, default: `true`) Open the location list @@ -929,8 +929,8 @@ setqflist({opts}) *vim.diagnostic.setqflist()* Parameters: ~ • {opts} (`table?`) Configuration table with the following keys: - • {namespace}? (`integer`) Only add diagnostics from the given - namespace. + • {namespace}? (`integer[]|integer`) Only add diagnostics from + the given namespace(s). • {open}? (`boolean`, default: `true`) Open quickfix list after setting. • {title}? (`string`) Title of quickfix list. Defaults to diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua index ca2754481d..1e6a94090d 100644 --- a/runtime/lua/vim/diagnostic.lua +++ b/runtime/lua/vim/diagnostic.lua @@ -2348,8 +2348,8 @@ end --- @class vim.diagnostic.setqflist.Opts --- @inlinedoc --- ---- Only add diagnostics from the given namespace. ---- @field namespace? integer +--- Only add diagnostics from the given namespace(s). +--- @field namespace? integer[]|integer --- --- Open quickfix list after setting. --- (default: `true`) @@ -2373,8 +2373,8 @@ end --- @class vim.diagnostic.setloclist.Opts --- @inlinedoc --- ---- Only add diagnostics from the given namespace. ---- @field namespace? integer +--- Only add diagnostics from the given namespace(s). +--- @field namespace? integer[]|integer --- --- Window number to set location list for. --- (default: `0`) diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index 2f43d49ef7..73b865d91a 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -3428,6 +3428,26 @@ describe('vim.diagnostic', function() assert(loc_list[1].lnum < loc_list[2].lnum) end) + + it('sets diagnostics from the specified namespaces', function() + local loc_list = exec_lua(function() + vim.api.nvim_win_set_buf(0, _G.diagnostic_bufnr) + + vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, { + _G.make_error('Error here!', 1, 1, 1, 1), + }) + vim.diagnostic.set(_G.other_ns, _G.diagnostic_bufnr, { + _G.make_warning('Error there!', 2, 2, 2, 2), + }) + + vim.diagnostic.setloclist({ namespace = { _G.diagnostic_ns } }) + + return vim.fn.getloclist(0) + end) + + eq(1, #loc_list) + eq('Error here!', loc_list[1].text) + end) end) describe('setqflist()', function()