mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge #28227 feat(diagnostic): is_enabled, enable(…, enable:boolean)
This commit is contained in:
commit
3065e2fa5d
@ -80,12 +80,15 @@ HIGHLIGHTS
|
|||||||
- *hl-VertSplit* Use |hl-WinSeparator| instead.
|
- *hl-VertSplit* Use |hl-WinSeparator| instead.
|
||||||
|
|
||||||
LSP DIAGNOSTICS
|
LSP DIAGNOSTICS
|
||||||
|
- *vim.diagnostic.disable()* Use |vim.diagnostic.enable()|
|
||||||
|
- *vim.diagnostic.is_disabled()* Use |vim.diagnostic.is_enabled()|
|
||||||
|
|
||||||
For each of the functions below, use the corresponding function in
|
For each of the functions below, use the corresponding function in
|
||||||
|vim.diagnostic| instead (unless otherwise noted). For example, use
|
|vim.diagnostic| instead (unless otherwise noted). For example, use
|
||||||
|vim.diagnostic.get()| instead of |vim.lsp.diagnostic.get()|.
|
|vim.diagnostic.get()| instead of |vim.lsp.diagnostic.get()|.
|
||||||
|
|
||||||
- *vim.lsp.diagnostic.clear()* Use |vim.diagnostic.hide()| instead.
|
- *vim.lsp.diagnostic.clear()* Use |vim.diagnostic.hide()| instead.
|
||||||
- *vim.lsp.diagnostic.disable()*
|
- *vim.lsp.diagnostic.disable()* Use |vim.diagnostic.enable()| instead.
|
||||||
- *vim.lsp.diagnostic.display()* Use |vim.diagnostic.show()| instead.
|
- *vim.lsp.diagnostic.display()* Use |vim.diagnostic.show()| instead.
|
||||||
- *vim.lsp.diagnostic.enable()*
|
- *vim.lsp.diagnostic.enable()*
|
||||||
- *vim.lsp.diagnostic.get()*
|
- *vim.lsp.diagnostic.get()*
|
||||||
|
@ -372,20 +372,25 @@ Use existing common {verb} names (actions) if possible:
|
|||||||
- create: Creates a new (non-trivial) thing (TODO: rename to "def"?)
|
- create: Creates a new (non-trivial) thing (TODO: rename to "def"?)
|
||||||
- del: Deletes a thing (or group of things)
|
- del: Deletes a thing (or group of things)
|
||||||
- detach: Dispose attached listener (TODO: rename to "un"?)
|
- detach: Dispose attached listener (TODO: rename to "un"?)
|
||||||
|
- enable: Enables/disables functionality.
|
||||||
- eval: Evaluates an expression
|
- eval: Evaluates an expression
|
||||||
- exec: Executes code
|
- exec: Executes code
|
||||||
- fmt: Formats
|
- fmt: Formats
|
||||||
- get: Gets things (often by a query)
|
- get: Gets things (often by a query)
|
||||||
- inspect: Presents a high-level, often interactive, view
|
- inspect: Presents a high-level, often interactive, view
|
||||||
|
- is_enabled: Checks if functionality is enabled.
|
||||||
- open: Opens something (a buffer, window, …)
|
- open: Opens something (a buffer, window, …)
|
||||||
- parse: Parses something into a structured form
|
- parse: Parses something into a structured form
|
||||||
- set: Sets a thing (or group of things)
|
- set: Sets a thing (or group of things)
|
||||||
- try_{verb}: Best-effort operation, failure returns null or error obj
|
- try_{verb}: Best-effort operation, failure returns null or error obj
|
||||||
|
|
||||||
Do NOT use these deprecated verbs:
|
Do NOT use these deprecated verbs:
|
||||||
|
- disable: Prefer `enable(enable: boolean)`.
|
||||||
|
- is_disabled: Prefer `is_enabled()`.
|
||||||
- list: Redundant with "get"
|
- list: Redundant with "get"
|
||||||
- show: Redundant with "print", "echo"
|
|
||||||
- notify: Redundant with "print", "echo"
|
- notify: Redundant with "print", "echo"
|
||||||
|
- show: Redundant with "print", "echo"
|
||||||
|
- toggle: Prefer `enable(not is_enabled())`.
|
||||||
|
|
||||||
Use consistent names for {noun} (nouns) in API functions: buffer is called
|
Use consistent names for {noun} (nouns) in API functions: buffer is called
|
||||||
"buf" everywhere, not "buffer" in some places and "buf" in others.
|
"buf" everywhere, not "buffer" in some places and "buf" in others.
|
||||||
|
@ -367,6 +367,13 @@ Lua module: vim.diagnostic *diagnostic-api*
|
|||||||
• {user_data}? (`any`) arbitrary data plugins can add
|
• {user_data}? (`any`) arbitrary data plugins can add
|
||||||
• {namespace}? (`integer`)
|
• {namespace}? (`integer`)
|
||||||
|
|
||||||
|
*vim.diagnostic.Filter*
|
||||||
|
Extends: |vim.diagnostic.Opts|
|
||||||
|
|
||||||
|
|
||||||
|
Fields: ~
|
||||||
|
• {ns_id}? (`integer`) Namespace
|
||||||
|
|
||||||
*vim.diagnostic.GetOpts*
|
*vim.diagnostic.GetOpts*
|
||||||
A table with the following keys:
|
A table with the following keys:
|
||||||
|
|
||||||
@ -616,23 +623,20 @@ count({bufnr}, {opts}) *vim.diagnostic.count()*
|
|||||||
(`table`) Table with actually present severity values as keys (see
|
(`table`) Table with actually present severity values as keys (see
|
||||||
|diagnostic-severity|) and integer counts as values.
|
|diagnostic-severity|) and integer counts as values.
|
||||||
|
|
||||||
disable({bufnr}, {namespace}) *vim.diagnostic.disable()*
|
enable({bufnr}, {enable}, {opts}) *vim.diagnostic.enable()*
|
||||||
Disable diagnostics in the given buffer.
|
Enables or disables diagnostics.
|
||||||
|
|
||||||
|
To "toggle", pass the inverse of `is_enabled()`: >lua
|
||||||
|
vim.diagnostic.enable(0, not vim.diagnostic.is_enabled())
|
||||||
|
<
|
||||||
|
|
||||||
Parameters: ~
|
Parameters: ~
|
||||||
• {bufnr} (`integer?`) Buffer number, or 0 for current buffer. When
|
• {bufnr} (`integer?`) Buffer number, or 0 for current buffer, or
|
||||||
omitted, disable diagnostics in all buffers.
|
`nil` for all buffers.
|
||||||
• {namespace} (`integer?`) Only disable diagnostics for the given
|
• {enable} (`boolean?`) true/nil to enable, false to disable
|
||||||
namespace.
|
• {opts} (`vim.diagnostic.Filter?`) Filter by these opts, or `nil`
|
||||||
|
for all. Only `ns_id` is supported, currently. See
|
||||||
enable({bufnr}, {namespace}) *vim.diagnostic.enable()*
|
|vim.diagnostic.Filter|.
|
||||||
Enable diagnostics in the given buffer.
|
|
||||||
|
|
||||||
Parameters: ~
|
|
||||||
• {bufnr} (`integer?`) Buffer number, or 0 for current buffer. When
|
|
||||||
omitted, enable diagnostics in all buffers.
|
|
||||||
• {namespace} (`integer?`) Only enable diagnostics for the given
|
|
||||||
namespace.
|
|
||||||
|
|
||||||
fromqflist({list}) *vim.diagnostic.fromqflist()*
|
fromqflist({list}) *vim.diagnostic.fromqflist()*
|
||||||
Convert a list of quickfix items to a list of diagnostics.
|
Convert a list of quickfix items to a list of diagnostics.
|
||||||
@ -733,7 +737,7 @@ hide({namespace}, {bufnr}) *vim.diagnostic.hide()*
|
|||||||
diagnostics, use |vim.diagnostic.reset()|.
|
diagnostics, use |vim.diagnostic.reset()|.
|
||||||
|
|
||||||
To hide diagnostics and prevent them from re-displaying, use
|
To hide diagnostics and prevent them from re-displaying, use
|
||||||
|vim.diagnostic.disable()|.
|
|vim.diagnostic.enable()|.
|
||||||
|
|
||||||
Parameters: ~
|
Parameters: ~
|
||||||
• {namespace} (`integer?`) Diagnostic namespace. When omitted, hide
|
• {namespace} (`integer?`) Diagnostic namespace. When omitted, hide
|
||||||
@ -741,14 +745,16 @@ hide({namespace}, {bufnr}) *vim.diagnostic.hide()*
|
|||||||
• {bufnr} (`integer?`) Buffer number, or 0 for current buffer. When
|
• {bufnr} (`integer?`) 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()*
|
is_enabled({bufnr}, {namespace}) *vim.diagnostic.is_enabled()*
|
||||||
Check whether diagnostics are disabled in a given buffer.
|
Check whether diagnostics are enabled.
|
||||||
|
|
||||||
|
Note: ~
|
||||||
|
• This API is pre-release (unstable).
|
||||||
|
|
||||||
Parameters: ~
|
Parameters: ~
|
||||||
• {bufnr} (`integer?`) Buffer number, or 0 for current buffer.
|
• {bufnr} (`integer?`) Buffer number, or 0 for current buffer.
|
||||||
• {namespace} (`integer?`) Diagnostic namespace. When omitted, checks
|
• {namespace} (`integer?`) Diagnostic namespace, or `nil` for all
|
||||||
if all diagnostics are disabled in {bufnr}. Otherwise,
|
diagnostics in {bufnr}.
|
||||||
only checks if diagnostics from {namespace} are disabled.
|
|
||||||
|
|
||||||
Return: ~
|
Return: ~
|
||||||
(`boolean`)
|
(`boolean`)
|
||||||
|
@ -162,7 +162,7 @@ The following new APIs or features were added.
|
|||||||
• |vim.diagnostic| now supports LSP DiagnosticsTag.
|
• |vim.diagnostic| now supports LSP DiagnosticsTag.
|
||||||
See: https://microsoft.github.io/language-server-protocol/specification/#diagnosticTag
|
See: https://microsoft.github.io/language-server-protocol/specification/#diagnosticTag
|
||||||
|
|
||||||
• |vim.diagnostic.is_disabled()| checks if diagnostics are disabled in a given
|
• vim.diagnostic.is_disabled() checks if diagnostics are disabled in a given
|
||||||
buffer or namespace.
|
buffer or namespace.
|
||||||
|
|
||||||
• Treesitter captures can now be transformed by directives. This will allow
|
• Treesitter captures can now be transformed by directives. This will allow
|
||||||
|
@ -328,6 +328,8 @@ The following new APIs and features were added.
|
|||||||
|vim.diagnostic.get()| when only the number of diagnostics is needed, but
|
|vim.diagnostic.get()| when only the number of diagnostics is needed, but
|
||||||
not the diagnostics themselves.
|
not the diagnostics themselves.
|
||||||
|
|
||||||
|
• Introduced |vim.diagnostic.is_enabled()|
|
||||||
|
|
||||||
• |vim.deepcopy()| has a `noref` argument to avoid hashing table values.
|
• |vim.deepcopy()| has a `noref` argument to avoid hashing table values.
|
||||||
|
|
||||||
• Terminal buffers emit a |TermRequest| autocommand event when the child
|
• Terminal buffers emit a |TermRequest| autocommand event when the child
|
||||||
@ -419,6 +421,9 @@ The following changes to existing APIs or features add new behavior.
|
|||||||
• |vim.diagnostic.get()| and |vim.diagnostic.count()| accept multiple
|
• |vim.diagnostic.get()| and |vim.diagnostic.count()| accept multiple
|
||||||
namespaces rather than just a single namespace.
|
namespaces rather than just a single namespace.
|
||||||
|
|
||||||
|
• |vim.diagnostic.enable()| gained new parameters, and the old signature is
|
||||||
|
deprecated.
|
||||||
|
|
||||||
• Extmarks now fully support multi-line ranges, and a single extmark can be
|
• 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()|
|
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
|
API function already allowed you to define such ranges, but highlight regions
|
||||||
@ -520,6 +525,10 @@ release.
|
|||||||
- |nvim_win_get_option()| Use |nvim_get_option_value()| instead.
|
- |nvim_win_get_option()| Use |nvim_get_option_value()| instead.
|
||||||
- |nvim_win_set_option()| Use |nvim_set_option_value()| instead.
|
- |nvim_win_set_option()| Use |nvim_set_option_value()| instead.
|
||||||
|
|
||||||
|
• vim.diagnostic functions:
|
||||||
|
- |vim.diagnostic.disable()|
|
||||||
|
- |vim.diagnostic.is_disabled()|
|
||||||
|
|
||||||
• vim.lsp functions:
|
• vim.lsp functions:
|
||||||
- |vim.lsp.util.get_progress_messages()| Use |vim.lsp.status()| instead.
|
- |vim.lsp.util.get_progress_messages()| Use |vim.lsp.status()| instead.
|
||||||
- |vim.lsp.get_active_clients()| Use |vim.lsp.get_clients()| instead.
|
- |vim.lsp.get_active_clients()| Use |vim.lsp.get_clients()| instead.
|
||||||
|
@ -239,6 +239,9 @@ local M = {}
|
|||||||
--- whole line the sign is placed in.
|
--- whole line the sign is placed in.
|
||||||
--- @field linehl? table<vim.diagnostic.Severity,string>
|
--- @field linehl? table<vim.diagnostic.Severity,string>
|
||||||
|
|
||||||
|
--- @class vim.diagnostic.Filter : vim.diagnostic.Opts
|
||||||
|
--- @field ns_id? integer Namespace
|
||||||
|
|
||||||
--- @nodoc
|
--- @nodoc
|
||||||
--- @enum vim.diagnostic.Severity
|
--- @enum vim.diagnostic.Severity
|
||||||
M.severity = {
|
M.severity = {
|
||||||
@ -1492,7 +1495,7 @@ end
|
|||||||
--- diagnostics, use |vim.diagnostic.reset()|.
|
--- diagnostics, use |vim.diagnostic.reset()|.
|
||||||
---
|
---
|
||||||
--- To hide diagnostics and prevent them from re-displaying, use
|
--- To hide diagnostics and prevent them from re-displaying, use
|
||||||
--- |vim.diagnostic.disable()|.
|
--- |vim.diagnostic.enable()|.
|
||||||
---
|
---
|
||||||
---@param namespace integer? Diagnostic namespace. When omitted, hide
|
---@param namespace integer? Diagnostic namespace. When omitted, hide
|
||||||
--- diagnostics from all namespaces.
|
--- diagnostics from all namespaces.
|
||||||
@ -1517,25 +1520,29 @@ function M.hide(namespace, bufnr)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Check whether diagnostics are disabled in a given buffer.
|
--- Check whether diagnostics are enabled.
|
||||||
---
|
---
|
||||||
---@param bufnr integer? Buffer number, or 0 for current buffer.
|
--- @param bufnr integer? Buffer number, or 0 for current buffer.
|
||||||
---@param namespace integer? Diagnostic namespace. When omitted, checks if
|
--- @param namespace integer? Diagnostic namespace, or `nil` for all diagnostics in {bufnr}.
|
||||||
--- all diagnostics are disabled in {bufnr}.
|
--- @return boolean
|
||||||
--- Otherwise, only checks if diagnostics from
|
--- @since 12
|
||||||
--- {namespace} are disabled.
|
function M.is_enabled(bufnr, namespace)
|
||||||
---@return boolean
|
|
||||||
function M.is_disabled(bufnr, namespace)
|
|
||||||
bufnr = get_bufnr(bufnr)
|
bufnr = get_bufnr(bufnr)
|
||||||
if namespace and M.get_namespace(namespace).disabled then
|
if namespace and M.get_namespace(namespace).disabled then
|
||||||
return true
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
if type(diagnostic_disabled[bufnr]) == 'table' then
|
if type(diagnostic_disabled[bufnr]) == 'table' then
|
||||||
return diagnostic_disabled[bufnr][namespace]
|
return not diagnostic_disabled[bufnr][namespace]
|
||||||
end
|
end
|
||||||
|
|
||||||
return diagnostic_disabled[bufnr] ~= nil
|
return diagnostic_disabled[bufnr] == nil
|
||||||
|
end
|
||||||
|
|
||||||
|
--- @deprecated use `vim.diagnostic.is_enabled()`
|
||||||
|
function M.is_disabled(bufnr, namespace)
|
||||||
|
vim.deprecate('vim.diagnostic.is_disabled()', 'vim.diagnostic.is_enabled()', '0.12', nil, false)
|
||||||
|
return not M.is_enabled(bufnr, namespace)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Display diagnostics for the given namespace and buffer.
|
--- Display diagnostics for the given namespace and buffer.
|
||||||
@ -1581,7 +1588,7 @@ function M.show(namespace, bufnr, diagnostics, opts)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if M.is_disabled(bufnr, namespace) then
|
if not M.is_enabled(bufnr, namespace) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1923,71 +1930,107 @@ function M.setloclist(opts)
|
|||||||
set_list(true, opts)
|
set_list(true, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Disable diagnostics in the given buffer.
|
--- @deprecated use `vim.diagnostic.enabled(…, false)`
|
||||||
---
|
|
||||||
---@param bufnr integer? Buffer number, or 0 for current buffer. When
|
|
||||||
--- omitted, disable diagnostics in all buffers.
|
|
||||||
---@param namespace integer? Only disable diagnostics for the given namespace.
|
|
||||||
function M.disable(bufnr, namespace)
|
function M.disable(bufnr, namespace)
|
||||||
vim.validate({ bufnr = { bufnr, 'n', true }, namespace = { namespace, 'n', true } })
|
vim.deprecate(
|
||||||
if bufnr == nil then
|
'vim.diagnostic.disable()',
|
||||||
if namespace == nil then
|
'vim.diagnostic.enabled(…, false)',
|
||||||
-- Disable everything (including as yet non-existing buffers and
|
'0.12',
|
||||||
-- namespaces) by setting diagnostic_disabled to an empty table and set
|
nil,
|
||||||
-- its metatable to always return true. This metatable is removed
|
false
|
||||||
-- in enable()
|
)
|
||||||
diagnostic_disabled = setmetatable({}, {
|
M.enable(bufnr, false, { ns_id = namespace })
|
||||||
__index = function()
|
|
||||||
return true
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
else
|
|
||||||
local ns = M.get_namespace(namespace)
|
|
||||||
ns.disabled = true
|
|
||||||
end
|
|
||||||
else
|
|
||||||
bufnr = get_bufnr(bufnr)
|
|
||||||
if namespace == nil then
|
|
||||||
diagnostic_disabled[bufnr] = true
|
|
||||||
else
|
|
||||||
if type(diagnostic_disabled[bufnr]) ~= 'table' then
|
|
||||||
diagnostic_disabled[bufnr] = {}
|
|
||||||
end
|
|
||||||
diagnostic_disabled[bufnr][namespace] = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
M.hide(namespace, bufnr)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Enable diagnostics in the given buffer.
|
--- Enables or disables diagnostics.
|
||||||
---
|
---
|
||||||
---@param bufnr integer? Buffer number, or 0 for current buffer. When
|
--- To "toggle", pass the inverse of `is_enabled()`:
|
||||||
--- omitted, enable diagnostics in all buffers.
|
---
|
||||||
---@param namespace integer? Only enable diagnostics for the given namespace.
|
--- ```lua
|
||||||
function M.enable(bufnr, namespace)
|
--- vim.diagnostic.enable(0, not vim.diagnostic.is_enabled())
|
||||||
vim.validate({ bufnr = { bufnr, 'n', true }, namespace = { namespace, 'n', true } })
|
--- ```
|
||||||
|
---
|
||||||
|
--- @param bufnr integer? Buffer number, or 0 for current buffer, or `nil` for all buffers.
|
||||||
|
--- @param enable (boolean|nil) true/nil to enable, false to disable
|
||||||
|
--- @param opts vim.diagnostic.Filter? Filter by these opts, or `nil` for all. Only `ns_id` is
|
||||||
|
--- supported, currently.
|
||||||
|
function M.enable(bufnr, enable, opts)
|
||||||
|
opts = opts or {}
|
||||||
|
if type(enable) == 'number' then
|
||||||
|
-- Legacy signature.
|
||||||
|
vim.deprecate(
|
||||||
|
'vim.diagnostic.enable(buf:number, namespace)',
|
||||||
|
'vim.diagnostic.enable(buf:number, enable:boolean, opts)',
|
||||||
|
'0.12',
|
||||||
|
nil,
|
||||||
|
false
|
||||||
|
)
|
||||||
|
opts.ns_id = enable
|
||||||
|
enable = true
|
||||||
|
end
|
||||||
|
vim.validate({
|
||||||
|
bufnr = { bufnr, 'n', true },
|
||||||
|
enable = {
|
||||||
|
enable,
|
||||||
|
function(o)
|
||||||
|
return o == nil or type(o) == 'boolean' or type(o) == 'number'
|
||||||
|
end,
|
||||||
|
'boolean or number (deprecated)',
|
||||||
|
},
|
||||||
|
opts = {
|
||||||
|
opts,
|
||||||
|
function(o)
|
||||||
|
return o == nil
|
||||||
|
or (
|
||||||
|
type(o) == 'table'
|
||||||
|
-- TODO(justinmk): support other `vim.diagnostic.Filter` fields.
|
||||||
|
and (vim.tbl_isempty(o) or vim.deep_equal(vim.tbl_keys(o), { 'ns_id' }))
|
||||||
|
)
|
||||||
|
end,
|
||||||
|
'vim.diagnostic.Filter table (only ns_id is supported currently)',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
enable = enable == nil and true or enable
|
||||||
|
|
||||||
if bufnr == nil then
|
if bufnr == nil then
|
||||||
if namespace == nil then
|
if opts.ns_id == nil then
|
||||||
-- Enable everything by setting diagnostic_disabled to an empty table
|
diagnostic_disabled = (
|
||||||
diagnostic_disabled = {}
|
enable
|
||||||
|
-- Enable everything by setting diagnostic_disabled to an empty table.
|
||||||
|
and {}
|
||||||
|
-- Disable everything (including as yet non-existing buffers and namespaces) by setting
|
||||||
|
-- diagnostic_disabled to an empty table and set its metatable to always return true.
|
||||||
|
or setmetatable({}, {
|
||||||
|
__index = function()
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
)
|
||||||
else
|
else
|
||||||
local ns = M.get_namespace(namespace)
|
local ns = M.get_namespace(opts.ns_id)
|
||||||
ns.disabled = false
|
ns.disabled = not enable
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
bufnr = get_bufnr(bufnr)
|
bufnr = get_bufnr(bufnr)
|
||||||
if namespace == nil then
|
if opts.ns_id == nil then
|
||||||
diagnostic_disabled[bufnr] = nil
|
diagnostic_disabled[bufnr] = (not enable) and true or nil
|
||||||
else
|
else
|
||||||
if type(diagnostic_disabled[bufnr]) ~= 'table' then
|
if type(diagnostic_disabled[bufnr]) ~= 'table' then
|
||||||
return
|
if enable then
|
||||||
|
return
|
||||||
|
else
|
||||||
|
diagnostic_disabled[bufnr] = {}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
diagnostic_disabled[bufnr][namespace] = nil
|
diagnostic_disabled[bufnr][opts.ns_id] = (not enable) and true or nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
M.show(namespace, bufnr)
|
if enable then
|
||||||
|
M.show(opts.ns_id, bufnr)
|
||||||
|
else
|
||||||
|
M.hide(opts.ns_id, bufnr)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Parse a diagnostic from a string.
|
--- Parse a diagnostic from a string.
|
||||||
|
@ -329,7 +329,7 @@ describe('vim.diagnostic', function()
|
|||||||
eq(
|
eq(
|
||||||
{ 1, 1, 2, 0, 2 },
|
{ 1, 1, 2, 0, 2 },
|
||||||
exec_lua [[
|
exec_lua [[
|
||||||
vim.diagnostic.disable(diagnostic_bufnr, diagnostic_ns)
|
vim.diagnostic.enable(diagnostic_bufnr, false, { ns_id = diagnostic_ns })
|
||||||
return {
|
return {
|
||||||
count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns),
|
count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns),
|
||||||
count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.WARN, other_ns),
|
count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.WARN, other_ns),
|
||||||
@ -344,7 +344,7 @@ describe('vim.diagnostic', function()
|
|||||||
eq(
|
eq(
|
||||||
all_highlights,
|
all_highlights,
|
||||||
exec_lua([[
|
exec_lua([[
|
||||||
vim.diagnostic.enable(diagnostic_bufnr, diagnostic_ns)
|
vim.diagnostic.enable(diagnostic_bufnr, true, { ns_id = diagnostic_ns })
|
||||||
return {
|
return {
|
||||||
count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns),
|
count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns),
|
||||||
count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.WARN, other_ns),
|
count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.WARN, other_ns),
|
||||||
@ -371,7 +371,7 @@ describe('vim.diagnostic', function()
|
|||||||
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, ns_1_diags)
|
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, ns_1_diags)
|
||||||
vim.diagnostic.set(other_ns, diagnostic_bufnr, ns_2_diags)
|
vim.diagnostic.set(other_ns, diagnostic_bufnr, ns_2_diags)
|
||||||
|
|
||||||
vim.diagnostic.disable(diagnostic_bufnr, diagnostic_ns)
|
vim.diagnostic.enable(diagnostic_bufnr, false, { ns_id = diagnostic_ns })
|
||||||
|
|
||||||
return {
|
return {
|
||||||
count_extmarks(diagnostic_bufnr, diagnostic_ns),
|
count_extmarks(diagnostic_bufnr, diagnostic_ns),
|
||||||
@ -383,8 +383,8 @@ describe('vim.diagnostic', function()
|
|||||||
eq(
|
eq(
|
||||||
{ 4, 0 },
|
{ 4, 0 },
|
||||||
exec_lua [[
|
exec_lua [[
|
||||||
vim.diagnostic.enable(diagnostic_bufnr, diagnostic_ns)
|
vim.diagnostic.enable(diagnostic_bufnr, true, { ns_id = diagnostic_ns })
|
||||||
vim.diagnostic.disable(diagnostic_bufnr, other_ns)
|
vim.diagnostic.enable(diagnostic_bufnr, false, { ns_id = other_ns })
|
||||||
|
|
||||||
return {
|
return {
|
||||||
count_extmarks(diagnostic_bufnr, diagnostic_ns),
|
count_extmarks(diagnostic_bufnr, diagnostic_ns),
|
||||||
@ -478,7 +478,7 @@ describe('vim.diagnostic', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
describe('enable() and disable()', function()
|
describe('enable() and disable()', function()
|
||||||
it('works without arguments', function()
|
it('without arguments', function()
|
||||||
local result = exec_lua [[
|
local result = exec_lua [[
|
||||||
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
||||||
|
|
||||||
@ -500,7 +500,7 @@ describe('vim.diagnostic', function()
|
|||||||
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
|
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
|
||||||
count_extmarks(diagnostic_bufnr, other_ns))
|
count_extmarks(diagnostic_bufnr, other_ns))
|
||||||
|
|
||||||
vim.diagnostic.disable()
|
vim.diagnostic.enable(nil, false)
|
||||||
|
|
||||||
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
|
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
|
||||||
count_extmarks(diagnostic_bufnr, other_ns))
|
count_extmarks(diagnostic_bufnr, other_ns))
|
||||||
@ -532,7 +532,7 @@ describe('vim.diagnostic', function()
|
|||||||
eq(4, result[4])
|
eq(4, result[4])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('works with only a buffer argument', function()
|
it('with buffer argument', function()
|
||||||
local result = exec_lua [[
|
local result = exec_lua [[
|
||||||
local other_bufnr = vim.api.nvim_create_buf(true, false)
|
local other_bufnr = vim.api.nvim_create_buf(true, false)
|
||||||
|
|
||||||
@ -561,7 +561,7 @@ describe('vim.diagnostic', function()
|
|||||||
count_extmarks(diagnostic_bufnr, other_ns) +
|
count_extmarks(diagnostic_bufnr, other_ns) +
|
||||||
count_extmarks(other_bufnr, diagnostic_ns))
|
count_extmarks(other_bufnr, diagnostic_ns))
|
||||||
|
|
||||||
vim.diagnostic.disable(diagnostic_bufnr)
|
vim.diagnostic.enable(diagnostic_bufnr, false)
|
||||||
|
|
||||||
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
|
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
|
||||||
count_extmarks(diagnostic_bufnr, other_ns) +
|
count_extmarks(diagnostic_bufnr, other_ns) +
|
||||||
@ -573,7 +573,7 @@ describe('vim.diagnostic', function()
|
|||||||
count_extmarks(diagnostic_bufnr, other_ns) +
|
count_extmarks(diagnostic_bufnr, other_ns) +
|
||||||
count_extmarks(other_bufnr, diagnostic_ns))
|
count_extmarks(other_bufnr, diagnostic_ns))
|
||||||
|
|
||||||
vim.diagnostic.disable(other_bufnr)
|
vim.diagnostic.enable(other_bufnr, false)
|
||||||
|
|
||||||
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
|
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
|
||||||
count_extmarks(diagnostic_bufnr, other_ns) +
|
count_extmarks(diagnostic_bufnr, other_ns) +
|
||||||
@ -588,7 +588,7 @@ describe('vim.diagnostic', function()
|
|||||||
eq(3, result[4])
|
eq(3, result[4])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('works with only a namespace argument', function()
|
it('with a namespace argument', function()
|
||||||
local result = exec_lua [[
|
local result = exec_lua [[
|
||||||
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
||||||
|
|
||||||
@ -610,17 +610,17 @@ describe('vim.diagnostic', function()
|
|||||||
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
|
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
|
||||||
count_extmarks(diagnostic_bufnr, other_ns))
|
count_extmarks(diagnostic_bufnr, other_ns))
|
||||||
|
|
||||||
vim.diagnostic.disable(nil, diagnostic_ns)
|
vim.diagnostic.enable(nil, false, { ns_id = diagnostic_ns })
|
||||||
|
|
||||||
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
|
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
|
||||||
count_extmarks(diagnostic_bufnr, other_ns))
|
count_extmarks(diagnostic_bufnr, other_ns))
|
||||||
|
|
||||||
vim.diagnostic.enable(nil, diagnostic_ns)
|
vim.diagnostic.enable(nil, true, { ns_id = diagnostic_ns })
|
||||||
|
|
||||||
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
|
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
|
||||||
count_extmarks(diagnostic_bufnr, other_ns))
|
count_extmarks(diagnostic_bufnr, other_ns))
|
||||||
|
|
||||||
vim.diagnostic.disable(nil, other_ns)
|
vim.diagnostic.enable(nil, false, { ns_id = other_ns })
|
||||||
|
|
||||||
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
|
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
|
||||||
count_extmarks(diagnostic_bufnr, other_ns))
|
count_extmarks(diagnostic_bufnr, other_ns))
|
||||||
@ -634,8 +634,11 @@ describe('vim.diagnostic', function()
|
|||||||
eq(2, result[4])
|
eq(2, result[4])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('works with both a buffer and a namespace argument', function()
|
--- @return table
|
||||||
local result = exec_lua [[
|
local function test_enable(legacy)
|
||||||
|
local result = exec_lua(
|
||||||
|
[[
|
||||||
|
local legacy = ...
|
||||||
local other_bufnr = vim.api.nvim_create_buf(true, false)
|
local other_bufnr = vim.api.nvim_create_buf(true, false)
|
||||||
|
|
||||||
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
||||||
@ -663,34 +666,68 @@ describe('vim.diagnostic', function()
|
|||||||
count_extmarks(diagnostic_bufnr, other_ns) +
|
count_extmarks(diagnostic_bufnr, other_ns) +
|
||||||
count_extmarks(other_bufnr, diagnostic_ns))
|
count_extmarks(other_bufnr, diagnostic_ns))
|
||||||
|
|
||||||
vim.diagnostic.disable(diagnostic_bufnr, diagnostic_ns)
|
if legacy then
|
||||||
|
vim.diagnostic.disable(diagnostic_bufnr, diagnostic_ns)
|
||||||
|
else
|
||||||
|
vim.diagnostic.enable(diagnostic_bufnr, false, { ns_id = diagnostic_ns })
|
||||||
|
end
|
||||||
|
|
||||||
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
|
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
|
||||||
count_extmarks(diagnostic_bufnr, other_ns) +
|
count_extmarks(diagnostic_bufnr, other_ns) +
|
||||||
count_extmarks(other_bufnr, diagnostic_ns))
|
count_extmarks(other_bufnr, diagnostic_ns))
|
||||||
|
|
||||||
vim.diagnostic.disable(diagnostic_bufnr, other_ns)
|
if legacy then
|
||||||
|
vim.diagnostic.disable(diagnostic_bufnr, other_ns)
|
||||||
|
else
|
||||||
|
vim.diagnostic.enable(diagnostic_bufnr, false, { ns_id = other_ns })
|
||||||
|
end
|
||||||
|
|
||||||
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
|
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
|
||||||
count_extmarks(diagnostic_bufnr, other_ns) +
|
count_extmarks(diagnostic_bufnr, other_ns) +
|
||||||
count_extmarks(other_bufnr, diagnostic_ns))
|
count_extmarks(other_bufnr, diagnostic_ns))
|
||||||
|
|
||||||
vim.diagnostic.enable(diagnostic_bufnr, diagnostic_ns)
|
if legacy then
|
||||||
|
vim.diagnostic.enable(diagnostic_bufnr, diagnostic_ns)
|
||||||
|
else
|
||||||
|
vim.diagnostic.enable(diagnostic_bufnr, true, { ns_id = diagnostic_ns })
|
||||||
|
end
|
||||||
|
|
||||||
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
|
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
|
||||||
count_extmarks(diagnostic_bufnr, other_ns) +
|
count_extmarks(diagnostic_bufnr, other_ns) +
|
||||||
count_extmarks(other_bufnr, diagnostic_ns))
|
count_extmarks(other_bufnr, diagnostic_ns))
|
||||||
|
|
||||||
-- Should have no effect
|
if legacy then
|
||||||
vim.diagnostic.disable(other_bufnr, other_ns)
|
-- Should have no effect
|
||||||
|
vim.diagnostic.disable(other_bufnr, other_ns)
|
||||||
|
else
|
||||||
|
-- Should have no effect
|
||||||
|
vim.diagnostic.enable(other_bufnr, false, { ns_id = other_ns })
|
||||||
|
end
|
||||||
|
|
||||||
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
|
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
|
||||||
count_extmarks(diagnostic_bufnr, other_ns) +
|
count_extmarks(diagnostic_bufnr, other_ns) +
|
||||||
count_extmarks(other_bufnr, diagnostic_ns))
|
count_extmarks(other_bufnr, diagnostic_ns))
|
||||||
|
|
||||||
return result
|
return result
|
||||||
]]
|
]],
|
||||||
|
legacy
|
||||||
|
)
|
||||||
|
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
it('with both buffer and namespace arguments', function()
|
||||||
|
local result = test_enable(false)
|
||||||
|
eq(4, result[1])
|
||||||
|
eq(2, result[2])
|
||||||
|
eq(1, result[3])
|
||||||
|
eq(3, result[4])
|
||||||
|
eq(3, result[5])
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('with both buffer and namespace arguments (deprecated signature)', function()
|
||||||
|
-- Exercise the legacy/deprecated signature.
|
||||||
|
local result = test_enable(true)
|
||||||
eq(4, result[1])
|
eq(4, result[1])
|
||||||
eq(2, result[2])
|
eq(2, result[2])
|
||||||
eq(1, result[3])
|
eq(1, result[3])
|
||||||
@ -1742,7 +1779,7 @@ describe('vim.diagnostic', function()
|
|||||||
eq(
|
eq(
|
||||||
0,
|
0,
|
||||||
exec_lua [[
|
exec_lua [[
|
||||||
vim.diagnostic.disable(diagnostic_bufnr, diagnostic_ns)
|
vim.diagnostic.enable(diagnostic_bufnr, false, { ns_id = diagnostic_ns })
|
||||||
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, {
|
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, {
|
||||||
make_error('Diagnostic From Server 1:1', 1, 1, 1, 1),
|
make_error('Diagnostic From Server 1:1', 1, 1, 1, 1),
|
||||||
})
|
})
|
||||||
@ -1753,7 +1790,7 @@ describe('vim.diagnostic', function()
|
|||||||
eq(
|
eq(
|
||||||
2,
|
2,
|
||||||
exec_lua [[
|
exec_lua [[
|
||||||
vim.diagnostic.enable(diagnostic_bufnr, diagnostic_ns)
|
vim.diagnostic.enable(diagnostic_bufnr, true, { ns_id = diagnostic_ns })
|
||||||
return count_extmarks(diagnostic_bufnr, diagnostic_ns)
|
return count_extmarks(diagnostic_bufnr, diagnostic_ns)
|
||||||
]]
|
]]
|
||||||
)
|
)
|
||||||
@ -2711,7 +2748,39 @@ describe('vim.diagnostic', function()
|
|||||||
)
|
)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('checks if diagnostics are disabled in a buffer', function()
|
it('is_enabled', function()
|
||||||
|
eq(
|
||||||
|
{ false, false, false, false },
|
||||||
|
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.enable(nil, false)
|
||||||
|
return {
|
||||||
|
vim.diagnostic.is_enabled(),
|
||||||
|
vim.diagnostic.is_enabled(diagnostic_bufnr),
|
||||||
|
vim.diagnostic.is_enabled(diagnostic_bufnr, diagnostic_ns),
|
||||||
|
vim.diagnostic.is_enabled(_, diagnostic_ns),
|
||||||
|
}
|
||||||
|
]]
|
||||||
|
)
|
||||||
|
|
||||||
|
eq(
|
||||||
|
{ true, true, true, true },
|
||||||
|
exec_lua [[
|
||||||
|
vim.diagnostic.enable()
|
||||||
|
return {
|
||||||
|
vim.diagnostic.is_enabled(),
|
||||||
|
vim.diagnostic.is_enabled(diagnostic_bufnr),
|
||||||
|
vim.diagnostic.is_enabled(diagnostic_bufnr, diagnostic_ns),
|
||||||
|
vim.diagnostic.is_enabled(_, diagnostic_ns),
|
||||||
|
}
|
||||||
|
]]
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('is_disabled (deprecated)', function()
|
||||||
eq(
|
eq(
|
||||||
{ true, true, true, true },
|
{ true, true, true, true },
|
||||||
exec_lua [[
|
exec_lua [[
|
||||||
|
Loading…
Reference in New Issue
Block a user