mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
feat(diagnostic): vim.diagnostic.is_disabled() #21527
This commit is contained in:
@@ -565,6 +565,18 @@ hide({namespace}, {bufnr}) *vim.diagnostic.hide()*
|
|||||||
• {bufnr} (number|nil) Buffer number, or 0 for current buffer. When
|
• {bufnr} (number|nil) Buffer number, or 0 for current buffer. When
|
||||||
omitted, hide diagnostics in all buffers.
|
omitted, hide diagnostics in all buffers.
|
||||||
|
|
||||||
|
is_disabled({bufnr}, {namespace}) *vim.diagnostic.is_disabled()*
|
||||||
|
Check whether diagnostics are disabled in a given buffer.
|
||||||
|
|
||||||
|
Parameters: ~
|
||||||
|
• {bufnr} (number|nil) Buffer number, or 0 for current buffer.
|
||||||
|
• {namespace} (number|nil) Diagnostic namespace. When omitted, checks if all diagnostics are
|
||||||
|
disabled in {bufnr}. Otherwise, only checks if
|
||||||
|
diagnostics from {namespace} are disabled.
|
||||||
|
|
||||||
|
Return: ~
|
||||||
|
(boolean)
|
||||||
|
|
||||||
*vim.diagnostic.match()*
|
*vim.diagnostic.match()*
|
||||||
match({str}, {pat}, {groups}, {severity_map}, {defaults})
|
match({str}, {pat}, {groups}, {severity_map}, {defaults})
|
||||||
Parse a diagnostic from a string.
|
Parse a diagnostic from a string.
|
||||||
|
@@ -135,6 +135,9 @@ The following new APIs or features were added.
|
|||||||
|
|
||||||
See https://github.com/neovim/neovim/pull/14537.
|
See https://github.com/neovim/neovim/pull/14537.
|
||||||
|
|
||||||
|
• |vim.diagnostic.is_disabled()| checks if diagnostics are disabled in a given
|
||||||
|
buffer or namespace.
|
||||||
|
|
||||||
• |--remote-ui| option was added to connect to a remote instance and display
|
• |--remote-ui| option was added to connect to a remote instance and display
|
||||||
in it in a |TUI| in the local terminal. This can be used run a headless nvim
|
in it in a |TUI| in the local terminal. This can be used run a headless nvim
|
||||||
instance in the background and display its UI on demand, which previously
|
instance in the background and display its UI on demand, which previously
|
||||||
|
@@ -251,19 +251,6 @@ local function get_bufnr(bufnr)
|
|||||||
return bufnr
|
return bufnr
|
||||||
end
|
end
|
||||||
|
|
||||||
---@private
|
|
||||||
local function is_disabled(namespace, bufnr)
|
|
||||||
local ns = M.get_namespace(namespace)
|
|
||||||
if ns.disabled then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
if type(diagnostic_disabled[bufnr]) == 'table' then
|
|
||||||
return diagnostic_disabled[bufnr][namespace]
|
|
||||||
end
|
|
||||||
return diagnostic_disabled[bufnr]
|
|
||||||
end
|
|
||||||
|
|
||||||
---@private
|
---@private
|
||||||
local function diagnostic_lines(diagnostics)
|
local function diagnostic_lines(diagnostics)
|
||||||
if not diagnostics then
|
if not diagnostics then
|
||||||
@@ -1119,6 +1106,27 @@ function M.hide(namespace, bufnr)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Check whether diagnostics are disabled in a given buffer.
|
||||||
|
---
|
||||||
|
---@param bufnr number|nil Buffer number, or 0 for current buffer.
|
||||||
|
---@param namespace number|nil Diagnostic namespace. When omitted, checks if
|
||||||
|
--- all diagnostics are disabled in {bufnr}.
|
||||||
|
--- Otherwise, only checks if diagnostics from
|
||||||
|
--- {namespace} are disabled.
|
||||||
|
---@return boolean
|
||||||
|
function M.is_disabled(bufnr, namespace)
|
||||||
|
bufnr = get_bufnr(bufnr)
|
||||||
|
if namespace and M.get_namespace(namespace).disabled then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
if type(diagnostic_disabled[bufnr]) == 'table' then
|
||||||
|
return diagnostic_disabled[bufnr][namespace]
|
||||||
|
end
|
||||||
|
|
||||||
|
return diagnostic_disabled[bufnr] ~= nil
|
||||||
|
end
|
||||||
|
|
||||||
--- Display diagnostics for the given namespace and buffer.
|
--- Display diagnostics for the given namespace and buffer.
|
||||||
---
|
---
|
||||||
---@param namespace number|nil Diagnostic namespace. When omitted, show
|
---@param namespace number|nil Diagnostic namespace. When omitted, show
|
||||||
@@ -1162,7 +1170,7 @@ function M.show(namespace, bufnr, diagnostics, opts)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if is_disabled(namespace, bufnr) then
|
if M.is_disabled(bufnr, namespace) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@@ -2124,5 +2124,31 @@ end)
|
|||||||
return vim.g.diagnostic_autocmd_triggered == diagnostic_bufnr
|
return vim.g.diagnostic_autocmd_triggered == diagnostic_bufnr
|
||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it("checks if diagnostics are disabled in a buffer", function()
|
||||||
|
eq({true, true, true , true}, exec_lua [[
|
||||||
|
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, {
|
||||||
|
make_error('Diagnostic #1', 1, 1, 1, 1),
|
||||||
|
})
|
||||||
|
vim.api.nvim_set_current_buf(diagnostic_bufnr)
|
||||||
|
vim.diagnostic.disable()
|
||||||
|
return {
|
||||||
|
vim.diagnostic.is_disabled(),
|
||||||
|
vim.diagnostic.is_disabled(diagnostic_bufnr),
|
||||||
|
vim.diagnostic.is_disabled(diagnostic_bufnr, diagnostic_ns),
|
||||||
|
vim.diagnostic.is_disabled(_, diagnostic_ns),
|
||||||
|
}
|
||||||
|
]])
|
||||||
|
|
||||||
|
eq({false, false, false , false}, exec_lua [[
|
||||||
|
vim.diagnostic.enable()
|
||||||
|
return {
|
||||||
|
vim.diagnostic.is_disabled(),
|
||||||
|
vim.diagnostic.is_disabled(diagnostic_bufnr),
|
||||||
|
vim.diagnostic.is_disabled(diagnostic_bufnr, diagnostic_ns),
|
||||||
|
vim.diagnostic.is_disabled(_, diagnostic_ns),
|
||||||
|
}
|
||||||
|
]])
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user