aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'runtime')
-rw-r--r--runtime/doc/deprecated.txt5
-rw-r--r--runtime/doc/develop.txt5
-rw-r--r--runtime/doc/diagnostic.txt38
-rw-r--r--runtime/doc/news-0.9.txt2
-rw-r--r--runtime/doc/news.txt8
-rw-r--r--runtime/lua/vim/diagnostic.lua132
6 files changed, 108 insertions, 82 deletions
diff --git a/runtime/doc/deprecated.txt b/runtime/doc/deprecated.txt
index 5ac4ad4ce2..1b57f34896 100644
--- a/runtime/doc/deprecated.txt
+++ b/runtime/doc/deprecated.txt
@@ -80,12 +80,15 @@ HIGHLIGHTS
- *hl-VertSplit* Use |hl-WinSeparator| instead.
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
|vim.diagnostic| instead (unless otherwise noted). For example, use
|vim.diagnostic.get()| instead of |vim.lsp.diagnostic.get()|.
- *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.enable()*
- *vim.lsp.diagnostic.get()*
diff --git a/runtime/doc/develop.txt b/runtime/doc/develop.txt
index 767f46ad1e..a7373c84b3 100644
--- a/runtime/doc/develop.txt
+++ b/runtime/doc/develop.txt
@@ -383,9 +383,12 @@ Use existing common {verb} names (actions) if possible:
- try_{verb}: Best-effort operation, failure returns null or error obj
Do NOT use these deprecated verbs:
+ - disable: Prefer `enable(enable: boolean)`.
+ - is_disabled: Prefer `is_enabled()`.
- list: Redundant with "get"
- - show: 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
"buf" everywhere, not "buffer" in some places and "buf" in others.
diff --git a/runtime/doc/diagnostic.txt b/runtime/doc/diagnostic.txt
index a9172119d0..1f3f1c80fe 100644
--- a/runtime/doc/diagnostic.txt
+++ b/runtime/doc/diagnostic.txt
@@ -616,23 +616,19 @@ count({bufnr}, {opts}) *vim.diagnostic.count()*
(`table`) Table with actually present severity values as keys (see
|diagnostic-severity|) and integer counts as values.
-disable({bufnr}, {namespace}) *vim.diagnostic.disable()*
- Disable diagnostics in the given buffer.
+enable({bufnr}, {namespace}, {enable}) *vim.diagnostic.enable()*
+ Enables or disables diagnostics.
- Parameters: ~
- • {bufnr} (`integer?`) Buffer number, or 0 for current buffer. When
- omitted, disable diagnostics in all buffers.
- • {namespace} (`integer?`) Only disable diagnostics for the given
- namespace.
-
-enable({bufnr}, {namespace}) *vim.diagnostic.enable()*
- Enable diagnostics in the given buffer.
+ To "toggle", pass the inverse of `is_enabled()`: >lua
+ vim.diagnostic.enable(0, not vim.diagnostic.is_enabled())
+<
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.
+ • {bufnr} (`integer?`) Buffer number, or 0 for current buffer, or
+ `nil` for all buffers.
+ • {namespace} (`integer?`) Only for the given namespace, or `nil` for
+ all.
+ • {enable} (`boolean?`) true/nil to enable, false to disable
fromqflist({list}) *vim.diagnostic.fromqflist()*
Convert a list of quickfix items to a list of diagnostics.
@@ -733,7 +729,7 @@ hide({namespace}, {bufnr}) *vim.diagnostic.hide()*
diagnostics, use |vim.diagnostic.reset()|.
To hide diagnostics and prevent them from re-displaying, use
- |vim.diagnostic.disable()|.
+ |vim.diagnostic.enable()|.
Parameters: ~
• {namespace} (`integer?`) Diagnostic namespace. When omitted, hide
@@ -741,14 +737,16 @@ hide({namespace}, {bufnr}) *vim.diagnostic.hide()*
• {bufnr} (`integer?`) Buffer number, or 0 for current buffer. When
omitted, hide diagnostics in all buffers.
-is_disabled({bufnr}, {namespace}) *vim.diagnostic.is_disabled()*
- Check whether diagnostics are disabled in a given buffer.
+is_enabled({bufnr}, {namespace}) *vim.diagnostic.is_enabled()*
+ Check whether diagnostics are enabled.
+
+ Note: ~
+ • This API is pre-release (unstable).
Parameters: ~
• {bufnr} (`integer?`) Buffer number, or 0 for current buffer.
- • {namespace} (`integer?`) Diagnostic namespace. When omitted, checks
- if all diagnostics are disabled in {bufnr}. Otherwise,
- only checks if diagnostics from {namespace} are disabled.
+ • {namespace} (`integer?`) Diagnostic namespace, or `nil` for all
+ diagnostics in {bufnr}.
Return: ~
(`boolean`)
diff --git a/runtime/doc/news-0.9.txt b/runtime/doc/news-0.9.txt
index 789bc9e0bc..f1f3ac6954 100644
--- a/runtime/doc/news-0.9.txt
+++ b/runtime/doc/news-0.9.txt
@@ -162,7 +162,7 @@ The following new APIs or features were added.
• |vim.diagnostic| now supports LSP DiagnosticsTag.
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.
• Treesitter captures can now be transformed by directives. This will allow
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt
index ae5f808a9c..8609d84506 100644
--- a/runtime/doc/news.txt
+++ b/runtime/doc/news.txt
@@ -328,6 +328,8 @@ The following new APIs and features were added.
|vim.diagnostic.get()| when only the number of diagnostics is needed, but
not the diagnostics themselves.
+• Introduced |vim.diagnostic.is_enabled()|
+
• |vim.deepcopy()| has a `noref` argument to avoid hashing table values.
• Terminal buffers emit a |TermRequest| autocommand event when the child
@@ -419,6 +421,8 @@ The following changes to existing APIs or features add new behavior.
• |vim.diagnostic.get()| and |vim.diagnostic.count()| accept multiple
namespaces rather than just a single namespace.
+• |vim.diagnostic.enable()| accepts an `enabled` boolean parameter.
+
• 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
@@ -520,6 +524,10 @@ release.
- |nvim_win_get_option()| Use |nvim_get_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.util.get_progress_messages()| Use |vim.lsp.status()| instead.
- |vim.lsp.get_active_clients()| Use |vim.lsp.get_clients()| instead.
diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua
index 57491d155d..26374aa055 100644
--- a/runtime/lua/vim/diagnostic.lua
+++ b/runtime/lua/vim/diagnostic.lua
@@ -1492,7 +1492,7 @@ end
--- diagnostics, use |vim.diagnostic.reset()|.
---
--- To hide diagnostics and prevent them from re-displaying, use
---- |vim.diagnostic.disable()|.
+--- |vim.diagnostic.enable()|.
---
---@param namespace integer? Diagnostic namespace. When omitted, hide
--- diagnostics from all namespaces.
@@ -1517,25 +1517,35 @@ function M.hide(namespace, bufnr)
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 namespace integer? 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)
+--- @param bufnr integer? Buffer number, or 0 for current buffer.
+--- @param namespace integer? Diagnostic namespace, or `nil` for all diagnostics in {bufnr}.
+--- @return boolean
+--- @since 12
+function M.is_enabled(bufnr, namespace)
bufnr = get_bufnr(bufnr)
if namespace and M.get_namespace(namespace).disabled then
- return true
+ return false
end
if type(diagnostic_disabled[bufnr]) == 'table' then
- return diagnostic_disabled[bufnr][namespace]
+ return not diagnostic_disabled[bufnr][namespace]
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(
+ 'Defining diagnostic signs with :sign-define or sign_define()',
+ 'vim.diagnostic.is_enabled()',
+ '0.12',
+ nil,
+ false
+ )
+ return not M.is_enabled(bufnr, namespace)
end
--- Display diagnostics for the given namespace and buffer.
@@ -1923,71 +1933,75 @@ function M.setloclist(opts)
set_list(true, opts)
end
---- Disable diagnostics in the given buffer.
----
----@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.
+--- @deprecated use `vim.diagnostic.enabled(…, false)`
function M.disable(bufnr, namespace)
- vim.validate({ bufnr = { bufnr, 'n', true }, namespace = { namespace, 'n', true } })
- if bufnr == nil then
- if namespace == nil then
- -- 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. This metatable is removed
- -- in enable()
- diagnostic_disabled = setmetatable({}, {
- __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)
+ vim.deprecate(
+ 'vim.diagnostic.disable()',
+ 'vim.diagnostic.enabled(…, false)',
+ '0.12',
+ nil,
+ false
+ )
+ M.enable(bufnr, namespace, false)
end
---- Enable diagnostics in the given buffer.
+--- Enables or disables diagnostics.
---
----@param bufnr integer? Buffer number, or 0 for current buffer. When
---- omitted, enable diagnostics in all buffers.
----@param namespace integer? Only enable diagnostics for the given namespace.
-function M.enable(bufnr, namespace)
- vim.validate({ bufnr = { bufnr, 'n', true }, namespace = { namespace, 'n', true } })
+--- To "toggle", pass the inverse of `is_enabled()`:
+---
+--- ```lua
+--- vim.diagnostic.enable(0, not vim.diagnostic.is_enabled())
+--- ```
+---
+--- @param bufnr integer? Buffer number, or 0 for current buffer, or `nil` for all buffers.
+--- @param namespace integer? Only for the given namespace, or `nil` for all.
+--- @param enable (boolean|nil) true/nil to enable, false to disable
+function M.enable(bufnr, namespace, enable)
+ vim.validate({
+ bufnr = { bufnr, 'n', true },
+ namespace = { namespace, 'n', true },
+ enable = { enable, 'b', true },
+ })
+ enable = enable == nil and true or enable
if bufnr == nil then
if namespace == 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
local ns = M.get_namespace(namespace)
- ns.disabled = false
+ ns.disabled = not enable
end
else
bufnr = get_bufnr(bufnr)
if namespace == nil then
- diagnostic_disabled[bufnr] = nil
+ diagnostic_disabled[bufnr] = (not enable) and true or nil
else
if type(diagnostic_disabled[bufnr]) ~= 'table' then
- return
+ if enable then
+ return
+ else
+ diagnostic_disabled[bufnr] = {}
+ end
end
- diagnostic_disabled[bufnr][namespace] = nil
+ diagnostic_disabled[bufnr][namespace] = (not enable) and true or nil
end
end
- M.show(namespace, bufnr)
+ if enable then
+ M.show(namespace, bufnr)
+ else
+ M.hide(namespace, bufnr)
+ end
end
--- Parse a diagnostic from a string.