vim.diagnostic
TODO(lewis6991): deprecate some top level functions in favour of the submodule version e.g. vim.diagnostic.get_namespace() -> vim.diagnostic.namespace.get()
Methods25
function M.config(opts: vim.diagnostic.Opts | nil, namespace: nil | integer) -> vim.diagnostic.Opts | nil
Configure diagnostic options globally or for a specific diagnostic namespace.
Configuration can be specified globally, per-namespace, or ephemerally (i.e. only for a single call to |vim.diagnostic.set()| or |vim.diagnostic.show()|). Ephemeral configuration has highest priority, followed by namespace configuration, and finally global configuration.
For example, if a user enables virtual text globally with
vim.diagnostic.config({ virtual_text = true })
and a diagnostic producer sets diagnostics with
vim.diagnostic.set(ns, 0, diagnostics, { virtual_text = false })
then virtual text will not be enabled for those diagnostics.
optsvim.diagnostic.Opts | nilWhen omitted or
nil, retrieve the current configuration. Otherwise, a configuration table (see |vim.diagnostic.Opts|).namespacenil | integerUpdate the options for the given namespace. When omitted, update the global diagnostic options.
- vim.diagnostic.Opts | nil
: Current diagnostic config if {opts} is omitted.
function M.set(namespace: integer, buf: integer, diagnostics: vim.Diagnostic.Set[], opts: vim.diagnostic.Opts | nil) -> nil
Set diagnostics for the given namespace and buffer.
namespaceintegerThe diagnostic namespace
bufintegerBuffer number
diagnosticsvim.Diagnostic.Set[]optsvim.diagnostic.Opts | nilDisplay options to pass to |vim.diagnostic.show()|
- nil
function M.get_namespace(namespace: integer) -> vim.diagnostic.NS
Get namespace metadata.
namespaceintegerDiagnostic namespace
- vim.diagnostic.NS
: Namespace metadata
function M.get_namespaces() -> {integer, vim.diagnostic.NS}
Get current diagnostic namespaces.
- {integer, vim.diagnostic.NS}
: List of active diagnostic namespaces |vim.diagnostic|.
function M.get(buf: nil | integer, opts: vim.diagnostic.GetOpts | nil) -> vim.Diagnostic[]
Get current diagnostics.
Modifying diagnostics in the returned table has no effect. To set diagnostics in a buffer, use |vim.diagnostic.set()|.
bufnil | integerBuffer number to get diagnostics from. Use 0 for current buffer or nil for all buffers.
optsvim.diagnostic.GetOpts | nil
- vim.Diagnostic[]
: Fields
buf,end_lnum,end_col, andseverityare guaranteed to be present.
function M.count(buf: nil | integer, opts: vim.diagnostic.GetOpts | nil) -> {integer, integer}
Get current diagnostics count.
bufnil | integerBuffer number to get diagnostics from. Use 0 for current buffer or nil for all buffers.
optsvim.diagnostic.GetOpts | nil
- {integer, integer}
: Table with actually present severity values as keys (see |diagnostic-severity|) and integer counts as values.
function M.get_prev(opts: vim.diagnostic.JumpOpts | nil) -> vim.Diagnostic | nil
Get the previous diagnostic closest to the cursor position.
optsvim.diagnostic.JumpOpts | nil
- vim.Diagnostic | nil
: Previous diagnostic
function M.get_prev_pos(opts: vim.diagnostic.JumpOpts | nil) -> table | false
Deprecated
Return the position of the previous diagnostic in the current buffer.
optsvim.diagnostic.JumpOpts | nil
- table | false
: Previous diagnostic position as a
(row, col)tuple orfalseif there is no prior diagnostic.
function M.goto_prev(opts: vim.diagnostic.JumpOpts | nil) -> nil
Deprecated
Move to the previous diagnostic in the current buffer.
function M.get_next(opts: vim.diagnostic.JumpOpts | nil) -> vim.Diagnostic | nil
Get the next diagnostic closest to the cursor position.
optsvim.diagnostic.JumpOpts | nil
- vim.Diagnostic | nil
: Next diagnostic
function M.get_next_pos(opts: vim.diagnostic.JumpOpts | nil) -> table | false
Deprecated
Return the position of the next diagnostic in the current buffer.
optsvim.diagnostic.JumpOpts | nil
- table | false
: Next diagnostic position as a
(row, col)tuple or false if no next diagnostic.
function M.jump(opts: vim.diagnostic.JumpOpts) -> vim.Diagnostic | nil
function M.goto_next(opts: vim.diagnostic.JumpOpts | nil) -> nil
Deprecated
Move to the next diagnostic.
function M.hide(namespace: nil | integer, buf: nil | integer) -> nil
Hide currently displayed diagnostics.
This only clears the decorations displayed in the buffer. Diagnostics can be redisplayed with |vim.diagnostic.show()|. To completely remove diagnostics, use |vim.diagnostic.reset()|.
To hide diagnostics and prevent them from re-displaying, use |vim.diagnostic.enable()|.
namespacenil | integerDiagnostic namespace. When omitted, hide diagnostics from all namespaces.
bufnil | integerBuffer number, or 0 for current buffer. When omitted, hide diagnostics in all buffers.
- nil
function M.is_enabled(filter: vim.diagnostic.Filter | nil) -> boolean
Check whether diagnostics are enabled.
@since 12
function M.show(namespace: nil | integer, buf: nil | integer, diagnostics: vim.Diagnostic[] | nil, opts: vim.diagnostic.Opts | nil) -> nil
Display diagnostics for the given namespace and buffer.
namespacenil | integerDiagnostic namespace. When omitted, show diagnostics from all namespaces.
bufnil | integerBuffer number, or 0 for current buffer. When omitted, show diagnostics in all buffers.
diagnosticsvim.Diagnostic[] | nilThe diagnostics to display. When omitted, use the saved diagnostics for the given namespace and buffer. This can be used to display a list of diagnostics without saving them or to display only a subset of diagnostics. May not be used when {namespace} or {buf} is nil.
optsvim.diagnostic.Opts | nilDisplay options.
- nil
function M.open_float(opts: vim.diagnostic.Opts.Float | nil, ...) -> (float_bufnr nil | integer, winid nil | integer)
Show diagnostics in a floating window.
function M.reset(namespace: nil | integer, buf: nil | integer) -> nil
Remove all diagnostics from the given namespace.
Unlike |vim.diagnostic.hide()|, this function removes all saved diagnostics. They cannot be redisplayed using |vim.diagnostic.show()|. To simply remove diagnostic decorations in a way that they can be re-displayed, use |vim.diagnostic.hide()|.
namespacenil | integerDiagnostic namespace. When omitted, remove diagnostics from all namespaces.
bufnil | integerRemove diagnostics for the given buffer. When omitted, diagnostics are removed for all buffers.
- nil
function M.setqflist(opts: vim.diagnostic.setqflist.Opts | nil) -> nil
Add all diagnostics to the quickfix list.
function M.setloclist(opts: vim.diagnostic.setloclist.Opts | nil) -> nil
Add buffer diagnostics to the location list.
function M.enable(enable: nil | boolean, filter: vim.diagnostic.Filter | nil) -> nil
Enables or disables diagnostics.
To "toggle", pass the inverse of is_enabled():
vim.diagnostic.enable(not vim.diagnostic.is_enabled())
enablenil | booleantrue/nil to enable, false to disable
filtervim.diagnostic.Filter | nil
- nil
function M.match(str: string, pat: string, groups: string[], severity_map: table, defaults: nil | table) -> vim.Diagnostic | nil
Parse a diagnostic from a string.
For example, consider a line of output from a linter:
WARNING filename:27:3: Variable 'foo' does not exist
This can be parsed into |vim.Diagnostic| structure with:
local s = "WARNING filename:27:3: Variable 'foo' does not exist"
local pattern = "^(%w+) %w+:(%d+):(%d+): (.+)$"
local groups = { "severity", "lnum", "col", "message" }
vim.diagnostic.match(s, pattern, groups, { WARNING = vim.diagnostic.WARN })
strstringString to parse diagnostics from.
patstringLua pattern with capture groups.
groupsstring[]List of fields in a |vim.Diagnostic| structure to associate with captures from {pat}.
severity_maptableA table mapping the severity field from {groups} with an item from |vim.diagnostic.severity|.
defaultsnil | tableTable of default values for any fields not listed in {groups}. When omitted, numeric values default to 0 and "severity" defaults to ERROR.
- vim.Diagnostic | nil
: |vim.Diagnostic| structure or
nilif {pat} fails to match {str}.
function M.toqflist(diagnostics: vim.Diagnostic[]) -> table[]
Convert a list of diagnostics to a list of quickfix items that can be passed to |setqflist()| or |setloclist()|.
diagnosticsvim.Diagnostic[]
- table[]
: Quickfix list items |setqflist-what|
function M.fromqflist(list: vim.quickfix.entry[], opts: vim.diagnostic.fromqflist.Opts | nil) -> vim.Diagnostic[]
Convert a list of quickfix items to a list of diagnostics.
listvim.quickfix.entry[]List of quickfix items from |getqflist()| or |getloclist()|.
optsvim.diagnostic.fromqflist.Opts | nil
function M.status(buf: nil | integer) -> string
Returns formatted string with diagnostics for the current buffer. The severities with 0 diagnostics are left out. Example E:2 W:3 I:4 H:5
To customise appearance, see |vim.diagnostic.Opts.Status|.
bufnil | integerBuffer number to get diagnostics from. Defaults to 0 for the current buffer
- string
Fields9
M._config : vim.diagnostic._config
M._display : vim.diagnostic._display
M._float : vim.diagnostic._float
M._jump : vim.diagnostic._jump
M._severity : vim.diagnostic._severity
M._store : vim.diagnostic._store
M._handlers : vim.diagnostic._handlers
M.severity : vim.diagnostic.Severity
@nodoc
M.handlers : {string, vim.diagnostic.Handler}
@nodoc