feat(diagnostic): add enabled filter (#33981)

This commit is contained in:
Maria José Solano
2025-05-13 21:32:00 -05:00
committed by GitHub
parent 40b64e9100
commit 4fae013a21
4 changed files with 46 additions and 0 deletions

View File

@ -832,11 +832,24 @@ local function get_diagnostics(bufnr, opts, clamp)
return true
end
---@param b integer
---@param d vim.Diagnostic
local match_enablement = function(d, b)
if opts.enabled == nil then
return true
end
local enabled = M.is_enabled({ bufnr = b, ns_id = d.namespace })
return (enabled and opts.enabled) or (not enabled and not opts.enabled)
end
---@param b integer
---@param d vim.Diagnostic
local function add(b, d)
if
match_severity(d)
and match_enablement(d, b)
and (not opts.lnum or (opts.lnum >= d.lnum and opts.lnum <= (d.end_lnum or d.lnum)))
then
if clamp and api.nvim_buf_is_loaded(b) then
@ -1345,6 +1358,11 @@ end
---
--- See |diagnostic-severity|.
--- @field severity? vim.diagnostic.SeverityFilter
---
--- Limit diagnostics to only enabled or disabled. If nil, enablement is ignored.
--- See |vim.diagnostic.enable()|
--- (default: `nil`)
--- @field enabled? boolean
--- Configuration table with the keys listed below. Some parameters can have their default values
--- changed with |vim.diagnostic.config()|.