aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMayrom <32033791+nhruo123@users.noreply.github.com>2024-03-27 02:08:54 +0200
committerGitHub <noreply@github.com>2024-03-26 19:08:54 -0500
commitfc6d713dd8066f3132f7234a94ac059ae6d596a7 (patch)
tree25c60071862320fb8b0b0a600ee812ed0035cf11
parent77458e613b67b9e7607ae781bcfbdc2ff6b1b2ef (diff)
downloadrneovim-fc6d713dd8066f3132f7234a94ac059ae6d596a7.tar.gz
rneovim-fc6d713dd8066f3132f7234a94ac059ae6d596a7.tar.bz2
rneovim-fc6d713dd8066f3132f7234a94ac059ae6d596a7.zip
feat(diagnostic): add support for many namespaces filtering in GetOpts (#28045)
-rw-r--r--runtime/doc/diagnostic.txt3
-rw-r--r--runtime/doc/news.txt3
-rw-r--r--runtime/lua/vim/diagnostic.lua21
3 files changed, 21 insertions, 6 deletions
diff --git a/runtime/doc/diagnostic.txt b/runtime/doc/diagnostic.txt
index c9e783ca62..a9172119d0 100644
--- a/runtime/doc/diagnostic.txt
+++ b/runtime/doc/diagnostic.txt
@@ -371,7 +371,8 @@ Lua module: vim.diagnostic *diagnostic-api*
A table with the following keys:
Fields: ~
- • {namespace}? (`integer`) Limit diagnostics to the given namespace.
+ • {namespace}? (`integer[]|integer`) Limit diagnostics to one or more
+ namespaces.
• {lnum}? (`integer`) Limit diagnostics to the given line number.
• {severity}? (`vim.diagnostic.SeverityFilter`) See
|diagnostic-severity|.
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt
index 0222d547b0..1aee5c656b 100644
--- a/runtime/doc/news.txt
+++ b/runtime/doc/news.txt
@@ -408,6 +408,9 @@ The following changes to existing APIs or features add new behavior.
"virtual_text" table, which gives users more control over how diagnostic
virtual text is displayed.
+• |vim.diagnostic.get()| and |vim.diagnostic.count()| accept multiple
+ namespaces rather than just a single namespace.
+
• Extmarks now fully support multi-line ranges, and a single extmark can be
used to highlight a range of arbitrary length. The |nvim_buf_set_extmark()|
API function already allowed you to define such ranges, but highlight regions
diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua
index d5075d7d3d..57491d155d 100644
--- a/runtime/lua/vim/diagnostic.lua
+++ b/runtime/lua/vim/diagnostic.lua
@@ -682,6 +682,13 @@ local function get_diagnostics(bufnr, opts, clamp)
opts = opts or {}
local namespace = opts.namespace
+
+ if type(namespace) == 'number' then
+ namespace = { namespace }
+ end
+
+ ---@cast namespace integer[]
+
local diagnostics = {}
-- Memoized results of buf_line_count per bufnr
@@ -742,11 +749,15 @@ local function get_diagnostics(bufnr, opts, clamp)
end
elseif bufnr == nil then
for b, t in pairs(diagnostic_cache) do
- add_all_diags(b, t[namespace] or {})
+ for _, iter_namespace in ipairs(namespace) do
+ add_all_diags(b, t[iter_namespace] or {})
+ end
end
else
bufnr = get_bufnr(bufnr)
- add_all_diags(bufnr, diagnostic_cache[bufnr][namespace] or {})
+ for _, iter_namespace in ipairs(namespace) do
+ add_all_diags(bufnr, diagnostic_cache[bufnr][iter_namespace] or {})
+ end
end
if opts.severity then
@@ -785,7 +796,7 @@ end
--- @param search_forward boolean
--- @param bufnr integer
--- @param opts vim.diagnostic.GotoOpts
---- @param namespace integer
+--- @param namespace integer[]|integer
--- @return vim.Diagnostic?
local function next_diagnostic(position, search_forward, bufnr, opts, namespace)
position[1] = position[1] - 1
@@ -1115,8 +1126,8 @@ end
--- A table with the following keys:
--- @class vim.diagnostic.GetOpts
---
---- Limit diagnostics to the given namespace.
---- @field namespace? integer
+--- Limit diagnostics to one or more namespaces.
+--- @field namespace? integer[]|integer
---
--- Limit diagnostics to the given line number.
--- @field lnum? integer