robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

robinmerge: 1dc9728daa1d8a2702

master
48.8 KiB1089 linesraw
1*diagnostic.txt*   Diagnostics
2
3
4                            NVIM REFERENCE MANUAL
5
6
7Diagnostic framework                                     *vim.diagnostic*
8
9Nvim provides a framework for displaying errors or warnings from external
10tools, otherwise known as "diagnostics". These diagnostics can come from a
11variety of sources, such as linters or LSP servers. The diagnostic framework
12is an extension to existing error handling functionality such as the
13|quickfix| list.
14
15                                      Type |gO| to see the table of contents.
16
17==============================================================================
18QUICKSTART                                              *diagnostic-quickstart*
19
20Anything that reports diagnostics is referred to below as a "diagnostic
21producer". Diagnostic producers need only follow a few simple steps to
22report diagnostics:
23
241. Create a namespace |nvim_create_namespace()|. Note that the namespace must
25   have a name. Anonymous namespaces WILL NOT WORK.
262. (Optional) Configure options for the diagnostic namespace
27   |vim.diagnostic.config()|.
283. Generate diagnostics.
294. Set the diagnostics for the buffer |vim.diagnostic.set()|.
305. Repeat from step 3.
31
32Generally speaking, the API is split between functions meant to be used by
33diagnostic producers and those meant for diagnostic consumers (i.e. end users
34who want to read and view the diagnostics for a buffer).  The APIs for
35producers require a {namespace} as their first argument, while those for
36consumers generally do not require a namespace (though often one may be
37optionally supplied).  A good rule of thumb is that if a method is meant to
38modify the diagnostics for a buffer (e.g. |vim.diagnostic.set()|) then it
39requires a namespace.
40
41                                *vim.diagnostic.severity* *diagnostic-severity*
42The "severity" key in a diagnostic is one of the values defined in
43`vim.diagnostic.severity`: >
44
45    vim.diagnostic.severity.ERROR
46    vim.diagnostic.severity.WARN
47    vim.diagnostic.severity.INFO
48    vim.diagnostic.severity.HINT
49
50Functions that take a severity as an optional parameter (e.g.
51|vim.diagnostic.get()|) allow using severity names (like "ERROR") as well as
52values and accept one of three forms:
53
541. A single |vim.diagnostic.severity| value: >lua
55
56    vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN })
57
582. A table with a "min" or "max" key (or both). This form allows users to
59   specify a range of severities: >lua
60
61    vim.diagnostic.get(0, { severity = { min = vim.diagnostic.severity.WARN } })
623. A list-like table. This form allows filtering for specific severities: >lua
63
64    vim.diagnostic.get(0, { severity = {
65        vim.diagnostic.severity.WARN,
66        vim.diagnostic.severity.INFO,
67    } })
68<
69
70==============================================================================
71DEFAULTS                                              *diagnostic-defaults*
72
73These diagnostic keymaps are created unconditionally when Nvim starts:
74- `]d` jumps to the next diagnostic in the buffer. |]d-default|
75- `[d` jumps to the previous diagnostic in the buffer. |[d-default|
76- `]D` jumps to the last diagnostic in the buffer. |]D-default|
77- `[D` jumps to the first diagnostic in the buffer. |[D-default|
78- `<C-w>d` shows diagnostic at cursor in a floating window. |CTRL-W_d-default|
79
80==============================================================================
81HANDLERS                                                *diagnostic-handlers*
82
83Diagnostics are shown to the user with |vim.diagnostic.show()|. The display of
84diagnostics is managed through handlers. A handler is a table with a "show"
85and (optionally) a "hide" function. The "show" function has the signature
86>
87    function(namespace, bufnr, diagnostics, opts)
88<
89and is responsible for displaying or otherwise handling the given
90diagnostics. The "hide" function takes care of "cleaning up" any actions taken
91by the "show" function and has the signature
92>
93    function(namespace, bufnr)
94<
95Handlers can be configured with |vim.diagnostic.config()| and added by
96creating a new key in `vim.diagnostic.handlers` (see
97|diagnostic-handlers-example|).
98
99The {opts} table passed to a handler is the full set of configuration options
100(that is, it is not limited to just the options for the handler itself). The
101values in the table are already resolved (i.e. if a user specifies a
102function for a config option, the function has already been evaluated).
103
104If a diagnostic handler is configured with a "severity" key then the list of
105diagnostics passed to that handler will be filtered using the value of that
106key (see example below).
107
108Nvim provides these handlers by default: "virtual_text", "virtual_lines",
109"signs", and "underline".
110
111                                                *diagnostic-handlers-example*
112The example below creates a new handler that notifies the user of diagnostics
113with |vim.notify()|: >lua
114
115    -- It's good practice to namespace custom handlers to avoid collisions
116    vim.diagnostic.handlers["my/notify"] = {
117      show = function(namespace, bufnr, diagnostics, opts)
118        -- In our example, the opts table has a "log_level" option
119        local level = opts["my/notify"].log_level
120
121        local name = vim.diagnostic.get_namespace(namespace).name
122        local msg = string.format("%d diagnostics in buffer %d from %s",
123                                  #diagnostics,
124                                  bufnr,
125                                  name)
126        vim.notify(msg, level)
127      end,
128    }
129
130    -- Users can configure the handler
131    vim.diagnostic.config({
132      ["my/notify"] = {
133        log_level = vim.log.levels.INFO,
134
135        -- This handler will only receive "error" diagnostics.
136        severity = vim.diagnostic.severity.ERROR,
137      }
138    })
139<
140In this example, there is nothing to do when diagnostics are hidden, so we
141omit the "hide" function.
142
143Existing handlers can be overridden. For example, use the following to only
144show a sign for the highest severity diagnostic on a given line: >lua
145
146    -- Create a custom namespace. This will aggregate signs from all other
147    -- namespaces and only show the one with the highest severity on a
148    -- given line
149    local ns = vim.api.nvim_create_namespace("my_namespace")
150
151    -- Get a reference to the original signs handler
152    local orig_signs_handler = vim.diagnostic.handlers.signs
153
154    -- Override the built-in signs handler
155    vim.diagnostic.handlers.signs = {
156      show = function(_, bufnr, _, opts)
157        -- Get all diagnostics from the whole buffer rather than just the
158        -- diagnostics passed to the handler
159        local diagnostics = vim.diagnostic.get(bufnr)
160
161        -- Find the "worst" diagnostic per line
162        local max_severity_per_line = {}
163        for _, d in pairs(diagnostics) do
164          local m = max_severity_per_line[d.lnum]
165          if not m or d.severity < m.severity then
166            max_severity_per_line[d.lnum] = d
167          end
168        end
169
170        -- Pass the filtered diagnostics (with our custom namespace) to
171        -- the original handler
172        local filtered_diagnostics = vim.tbl_values(max_severity_per_line)
173        orig_signs_handler.show(ns, bufnr, filtered_diagnostics, opts)
174      end,
175      hide = function(_, bufnr)
176        orig_signs_handler.hide(ns, bufnr)
177      end,
178    }
179<
180
181                                          *diagnostic-toggle-virtual-lines-example*
182Diagnostic handlers can also be toggled. For example, you might want to toggle
183the `virtual_lines` handler with the following keymap: >lua
184
185    vim.keymap.set('n', 'gK', function()
186      local new_config = not vim.diagnostic.config().virtual_lines
187      vim.diagnostic.config({ virtual_lines = new_config })
188    end, { desc = 'Toggle diagnostic virtual_lines' })
189<
190
191                                            *diagnostic-on-jump-example*
192You can use the `on_jump` option from |vim.diagnostic.jump()| to show the
193diagnostic that was jumped to using a specific handler. For example, the
194following uses the `virtual_lines` handler when jumping to a diagnostic: >lua
195
196  --- @param diagnostic? vim.Diagnostic
197  --- @param bufnr integer
198  local function on_jump(diagnostic, bufnr)
199    if not diagnostic then return end
200
201    vim.diagnostic.show(
202      diagnostic.namespace,
203      bufnr,
204      { diagnostic },
205      { virtual_lines = { current_line = true }, virtual_text = false }
206    )
207  end
208
209  vim.diagnostic.config({ jump = { on_jump = on_jump } })
210<
211                                          *diagnostic-loclist-example*
212Whenever the |location-list| is opened, the following `show` handler will show
213the most recent diagnostics: >lua
214
215  vim.diagnostic.handlers.loclist = {
216    show = function(_, _, _, opts)
217      -- Generally don't want it to open on every update
218      opts.loclist.open = opts.loclist.open or false
219      local winid = vim.api.nvim_get_current_win()
220      vim.diagnostic.setloclist(opts.loclist)
221      vim.api.nvim_set_current_win(winid)
222    end
223  }
224<
225
226The handler accepts the same options as |vim.diagnostic.setloclist()| and can be
227configured using |vim.diagnostic.config()|: >lua
228
229  -- Open the location list on every diagnostic change (warnings/errors only).
230  vim.diagnostic.config({
231    loclist = {
232      open = true,
233      severity = { min = vim.diagnostic.severity.WARN },
234    }
235  })
236<
237
238==============================================================================
239HIGHLIGHTS                                              *diagnostic-highlights*
240
241All highlights defined for diagnostics begin with `Diagnostic` followed by
242the type of highlight (e.g., `Sign`, `Underline`, etc.) and the severity (e.g.
243`Error`, `Warn`, etc.)
244
245By default, highlights for signs, floating windows, and virtual text are linked to the
246corresponding default highlight. Underline highlights are not linked and use their
247own default highlight groups.
248
249For example, the default highlighting for |hl-DiagnosticSignError| is linked
250to |hl-DiagnosticError|. To change the default (and therefore the linked
251highlights), use the |:highlight| command: >vim
252
253    highlight DiagnosticError guifg="BrightRed"
254<
255                                                        *hl-DiagnosticError*
256DiagnosticError
257    Used as the base highlight group.
258    Other Diagnostic highlights link to this by default (except Underline)
259
260                                                        *hl-DiagnosticWarn*
261DiagnosticWarn
262    Used as the base highlight group.
263    Other Diagnostic highlights link to this by default (except Underline)
264
265                                                        *hl-DiagnosticInfo*
266DiagnosticInfo
267    Used as the base highlight group.
268    Other Diagnostic highlights link to this by default (except Underline)
269
270                                                        *hl-DiagnosticHint*
271DiagnosticHint
272    Used as the base highlight group.
273    Other Diagnostic highlights link to this by default (except Underline)
274
275                                                        *hl-DiagnosticOk*
276DiagnosticOk
277    Used as the base highlight group.
278    Other Diagnostic highlights link to this by default (except Underline)
279
280                                        *hl-DiagnosticVirtualTextError*
281DiagnosticVirtualTextError
282    Used for "Error" diagnostic virtual text.
283
284                                        *hl-DiagnosticVirtualTextWarn*
285DiagnosticVirtualTextWarn
286    Used for "Warn" diagnostic virtual text.
287
288                                                *hl-DiagnosticVirtualTextInfo*
289DiagnosticVirtualTextInfo
290    Used for "Info" diagnostic virtual text.
291
292                                                *hl-DiagnosticVirtualTextHint*
293DiagnosticVirtualTextHint
294    Used for "Hint" diagnostic virtual text.
295
296                                                *hl-DiagnosticVirtualTextOk*
297DiagnosticVirtualTextOk
298    Used for "Ok" diagnostic virtual text.
299
300                                            *hl-DiagnosticVirtualLinesError*
301DiagnosticVirtualLinesError
302    Used for "Error" diagnostic virtual lines.
303
304                                            *hl-DiagnosticVirtualLinesWarn*
305DiagnosticVirtualLinesWarn
306    Used for "Warn" diagnostic virtual lines.
307
308                                            *hl-DiagnosticVirtualLinesInfo*
309DiagnosticVirtualLinesInfo
310    Used for "Info" diagnostic virtual lines.
311
312                                            *hl-DiagnosticVirtualLinesHint*
313DiagnosticVirtualLinesHint
314    Used for "Hint" diagnostic virtual lines.
315
316                                                *hl-DiagnosticVirtualLinesOk*
317DiagnosticVirtualLinesOk
318    Used for "Ok" diagnostic virtual lines.
319
320                                                *hl-DiagnosticUnderlineError*
321DiagnosticUnderlineError
322    Used to underline "Error" diagnostics.
323
324                                                *hl-DiagnosticUnderlineWarn*
325DiagnosticUnderlineWarn
326    Used to underline "Warn" diagnostics.
327
328                                                *hl-DiagnosticUnderlineInfo*
329DiagnosticUnderlineInfo
330    Used to underline "Info" diagnostics.
331
332                                                *hl-DiagnosticUnderlineHint*
333DiagnosticUnderlineHint
334    Used to underline "Hint" diagnostics.
335
336                                                *hl-DiagnosticUnderlineOk*
337DiagnosticUnderlineOk
338    Used to underline "Ok" diagnostics.
339
340                                                *hl-DiagnosticFloatingError*
341DiagnosticFloatingError
342    Used to color "Error" diagnostic messages in diagnostics float.
343    See |vim.diagnostic.open_float()|
344
345                                                *hl-DiagnosticFloatingWarn*
346DiagnosticFloatingWarn
347    Used to color "Warn" diagnostic messages in diagnostics float.
348
349                                                *hl-DiagnosticFloatingInfo*
350DiagnosticFloatingInfo
351    Used to color "Info" diagnostic messages in diagnostics float.
352
353                                                *hl-DiagnosticFloatingHint*
354DiagnosticFloatingHint
355    Used to color "Hint" diagnostic messages in diagnostics float.
356
357                                                *hl-DiagnosticFloatingOk*
358DiagnosticFloatingOk
359    Used to color "Ok" diagnostic messages in diagnostics float.
360
361                                                *hl-DiagnosticSignError*
362DiagnosticSignError
363    Used for "Error" signs in sign column.
364
365                                                *hl-DiagnosticSignWarn*
366DiagnosticSignWarn
367    Used for "Warn" signs in sign column.
368
369                                                *hl-DiagnosticSignInfo*
370DiagnosticSignInfo
371    Used for "Info" signs in sign column.
372
373                                                *hl-DiagnosticSignHint*
374DiagnosticSignHint
375    Used for "Hint" signs in sign column.
376
377                                                *hl-DiagnosticSignOk*
378DiagnosticSignOk
379    Used for "Ok" signs in sign column.
380
381                                                *hl-DiagnosticDeprecated*
382DiagnosticDeprecated
383    Used for deprecated or obsolete code. Applied by the "underline" handler;
384    disabled when `vim.diagnostic.config({ underline = false })`.
385
386                                                *hl-DiagnosticUnnecessary*
387DiagnosticUnnecessary
388    Used for unnecessary or unused code. Applied by the "underline" handler;
389    disabled when `vim.diagnostic.config({ underline = false })`.
390
391==============================================================================
392SIGNS                                                   *diagnostic-signs*
393
394Signs are defined for each diagnostic severity. The default text for each sign
395is the first letter of the severity name (for example, "E" for ERROR). Signs
396can be customized with |vim.diagnostic.config()|. Example: >lua
397
398    -- Highlight entire line for errors
399    -- Highlight the line number for warnings
400    vim.diagnostic.config({
401        signs = {
402            text = {
403                [vim.diagnostic.severity.ERROR] = '',
404                [vim.diagnostic.severity.WARN] = '',
405            },
406            linehl = {
407                [vim.diagnostic.severity.ERROR] = 'ErrorMsg',
408            },
409            numhl = {
410                [vim.diagnostic.severity.WARN] = 'WarningMsg',
411            },
412        },
413    })
414
415When the "severity_sort" option is set (see |vim.diagnostic.config()|) the
416priority of each sign depends on the severity of the associated diagnostic.
417Otherwise, all signs have the same priority (the value of the "priority"
418option in the "signs" table of |vim.diagnostic.config()| or 10 if unset).
419
420==============================================================================
421EVENTS                                                  *diagnostic-events*
422
423                                                        *DiagnosticChanged*
424DiagnosticChanged       After diagnostics have changed. When used from Lua,
425                        the new diagnostics are passed to the autocmd
426                        callback in the "data" table. Triggered per buffer.
427
428Example: >lua
429
430    vim.api.nvim_create_autocmd('DiagnosticChanged', {
431      callback = function(ev)
432        local diagnostics = ev.data.diagnostics
433        vim.print(diagnostics)
434      end,
435    })
436<
437==============================================================================
438Lua module: vim.diagnostic                                    *diagnostic-api*
439
440*vim.Diagnostic*
441    Extends: |vim.Diagnostic.Set|
442
443                                                        *diagnostic-structure*
444
445    Diagnostics use |api-indexing| (i.e. 0-based rows, and columns given as
446    0-based byte indices). See also |vim.pos| and |vim.range| to convert
447    positions from other systems.
448
449    Fields: ~
450      • {bufnr}       (`integer`) Buffer number
451      • {col}         (`integer`) The starting column of the diagnostic
452                      (0-indexed)
453      • {end_col}     (`integer`) The final column of the diagnostic
454                      (0-indexed)
455      • {end_lnum}    (`integer`) The final line of the diagnostic (0-indexed)
456      • {namespace}?  (`integer`)
457      • {severity}    (`vim.diagnostic.Severity`) The severity of the
458                      diagnostic |vim.diagnostic.severity|
459
460*vim.Diagnostic.Set*
461    Diagnostics use the same indexing as the rest of the Nvim API (i.e.
462    0-based rows, and columns given as 0-based byte indices). |api-indexing|
463
464    Fields: ~
465      • {code}?       (`string|integer`) The diagnostic code
466      • {col}?        (`integer`, default: `0`) The starting column of the
467                      diagnostic (0-indexed)
468      • {end_col}?    (`integer`, default: `col`) The final column of the
469                      diagnostic (0-indexed)
470      • {end_lnum}?   (`integer`, default: `lnum`) The final line of the
471                      diagnostic (0-indexed)
472      • {lnum}        (`integer`) The starting line of the diagnostic
473                      (0-indexed)
474      • {message}     (`string`) The diagnostic text
475      • {severity}?   (`vim.diagnostic.Severity`, default: `vim.diagnostic.severity.ERROR`)
476                      The severity of the diagnostic |vim.diagnostic.severity|
477      • {source}?     (`string`) The source of the diagnostic
478      • {user_data}?  (`any`) arbitrary data plugins can add
479
480*vim.diagnostic.GetOpts*
481    A table with the following keys:
482
483    Fields: ~
484      • {enabled}?    (`boolean`, default: `nil`) Limit diagnostics to only
485                      enabled or disabled. If nil, enablement is ignored. See
486                      |vim.diagnostic.enable()|
487      • {lnum}?       (`integer`) Limit diagnostics to those spanning the
488                      specified line number (0-indexed, see
489                      |diagnostic-structure|).
490      • {namespace}?  (`integer[]|integer`) Limit diagnostics to one or more
491                      namespaces.
492      • {severity}?   (`vim.diagnostic.SeverityFilter`) See
493                      |diagnostic-severity|.
494
495*vim.diagnostic.JumpOpts*
496    Extends: |vim.diagnostic.GetOpts|
497
498    Configuration table with the keys listed below. Some parameters can have
499    their default values changed with |vim.diagnostic.config()|.
500
501    Fields: ~
502      • {count}?       (`integer`) The number of diagnostics to move by,
503                       starting from {pos}. A positive integer moves forward
504                       by {count} diagnostics, while a negative integer moves
505                       backward by {count} diagnostics. Mutually exclusive
506                       with {diagnostic}.
507      • {diagnostic}?  (`vim.Diagnostic`) The diagnostic to jump to. Mutually
508                       exclusive with {count}, {namespace}, and {severity}.
509      • {on_jump}?     (`fun(diagnostic:vim.Diagnostic?, bufnr:integer)`)
510                       Optional callback invoked with the diagnostic that was
511                       jumped to.
512      • {pos}?         (`[integer,integer]`) Cursor position as a `(row, col)`
513                       tuple. See |nvim_win_get_cursor()|. Used to find the
514                       nearest diagnostic when {count} is used. Only used when
515                       {count} is non-nil. Default is the current cursor
516                       position.
517      • {severity}?    (`vim.diagnostic.SeverityFilter`) See
518                       |diagnostic-severity|.
519      • {winid}?       (`integer`, default: `0`) Window ID
520      • {wrap}?        (`boolean`, default: `true`) Whether to loop around
521                       file or not. Similar to 'wrapscan'.
522
523*vim.diagnostic.NS*
524
525    Fields: ~
526      • {disabled}?  (`boolean`)
527      • {name}       (`string`)
528      • {opts}       (`vim.diagnostic.Opts`)
529      • {user_data}  (`table`)
530
531*vim.diagnostic.Opts*
532    Many of the configuration options below accept one of the following:
533    • `false`: Disable this feature
534    • `true`: Enable this feature, use default settings.
535    • `table`: Enable this feature with overrides. Use an empty table to use
536      default values.
537    • `function`: Function with signature (namespace, bufnr) that returns any
538      of the above.
539
540    Fields: ~
541      • {float}?             (`boolean|vim.diagnostic.Opts.Float|fun(namespace?: integer|integer[], bufnr:integer): vim.diagnostic.Opts.Float`)
542                             Options for floating windows. See
543                             |vim.diagnostic.Opts.Float|.
544      • {jump}?              (`vim.diagnostic.Opts.Jump`) Default values for
545                             |vim.diagnostic.jump()|. See
546                             |vim.diagnostic.Opts.Jump|.
547      • {severity_sort}?     (`boolean|{reverse?:boolean}`, default: `false`)
548                             Sort diagnostics by severity. This affects the
549                             order in which signs, virtual text, and
550                             highlights are displayed. When true, higher
551                             severities are displayed before lower severities
552                             (e.g. ERROR is displayed before WARN). Options:
553                             • {reverse}? (boolean) Reverse sort order
554      • {signs}?             (`boolean|vim.diagnostic.Opts.Signs|fun(namespace: integer, bufnr:integer): vim.diagnostic.Opts.Signs`, default: `true`)
555                             Use signs for diagnostics |diagnostic-signs|.
556      • {status}?            (`vim.diagnostic.Opts.Status`) Options for the
557                             statusline component.
558      • {underline}?         (`boolean|vim.diagnostic.Opts.Underline|fun(namespace: integer, bufnr:integer): vim.diagnostic.Opts.Underline`, default: `true`)
559                             Used to call attention to a diagnostic
560                             ("underline" is a misnomer). Controls the
561                             |hl-DiagnosticUnnecessary| and
562                             |hl-DiagnosticDeprecated| highlights.
563      • {update_in_insert}?  (`boolean`, default: `false`) Update diagnostics
564                             in Insert mode (if `false`, diagnostics are
565                             updated on |InsertLeave|)
566      • {virtual_lines}?     (`boolean|vim.diagnostic.Opts.VirtualLines|fun(namespace: integer, bufnr:integer): vim.diagnostic.Opts.VirtualLines`, default: `false`)
567                             Use virtual lines for diagnostics.
568      • {virtual_text}?      (`boolean|vim.diagnostic.Opts.VirtualText|fun(namespace: integer, bufnr:integer): vim.diagnostic.Opts.VirtualText`, default: `false`)
569                             Use virtual text for diagnostics. If multiple
570                             diagnostics are set for a namespace, one prefix
571                             per diagnostic + the last diagnostic message are
572                             shown.
573
574*vim.diagnostic.Opts.Float*
575    Extends: |vim.lsp.util.open_floating_preview.Opts|
576
577
578    Fields: ~
579      • {bufnr}?          (`integer`, default: current buffer) Buffer number
580                          to show diagnostics from.
581      • {format}?         (`fun(diagnostic:vim.Diagnostic): string?`) A
582                          function that takes a diagnostic as input and
583                          returns a string or nil. If the return value is nil,
584                          the diagnostic is not displayed by the handler. Else
585                          the output text is used to display the diagnostic.
586                          Overrides the setting from
587                          |vim.diagnostic.config()|.
588      • {header}?         (`string|[string,any]`) String to use as the header
589                          for the floating window. If a table, it is
590                          interpreted as a `[text, hl_group]` tuple. Overrides
591                          the setting from |vim.diagnostic.config()|.
592      • {namespace}?      (`integer|integer[]`) Limit diagnostics to the given
593                          namespace(s).
594      • {pos}?            (`integer|[integer,integer]`) If {scope} is "line"
595                          or "cursor", use this position rather than the
596                          cursor position. If a number, interpreted as a line
597                          number; otherwise, a (row, col) tuple.
598      • {prefix}?         (`string|table|(fun(diagnostic:vim.Diagnostic,i:integer,total:integer): string, string)`)
599                          Prefix each diagnostic in the floating window:
600                          • If a `function`, {i} is the index of the
601                            diagnostic being evaluated and {total} is the
602                            total number of diagnostics displayed in the
603                            window. The function should return a `string`
604                            which is prepended to each diagnostic in the
605                            window as well as an (optional) highlight group
606                            which will be used to highlight the prefix.
607                          • If a `table`, it is interpreted as a
608                            `[text, hl_group]` tuple as in |nvim_echo()|
609                          • If a `string`, it is prepended to each diagnostic
610                            in the window with no highlight. Overrides the
611                            setting from |vim.diagnostic.config()|.
612      • {scope}?          (`'line'|'buffer'|'cursor'|'c'|'l'|'b'`, default:
613                          `line`) Show diagnostics from the whole buffer
614                          (`buffer`), the current cursor line (`line`), or the
615                          current cursor position (`cursor`). Shorthand
616                          versions are also accepted (`c` for `cursor`, `l`
617                          for `line`, `b` for `buffer`).
618      • {severity}?       (`vim.diagnostic.SeverityFilter`) See
619                          |diagnostic-severity|. Overrides the setting from
620                          |vim.diagnostic.config()|.
621      • {severity_sort}?  (`boolean|{reverse?:boolean}`, default: `false`)
622                          Sort diagnostics by severity. Overrides the setting
623                          from |vim.diagnostic.config()|.
624      • {source}?         (`boolean|'if_many'`) Include the diagnostic source
625                          in the message. Use "if_many" to only show sources
626                          if there is more than one source of diagnostics in
627                          the buffer. Otherwise, any truthy value means to
628                          always show the diagnostic source. Overrides the
629                          setting from |vim.diagnostic.config()|.
630      • {suffix}?         (`string|table|(fun(diagnostic:vim.Diagnostic,i:integer,total:integer): string, string)`)
631                          Same as {prefix}, but appends the text to the
632                          diagnostic instead of prepending it. Overrides the
633                          setting from |vim.diagnostic.config()|.
634
635*vim.diagnostic.Opts.Jump*
636
637    Fields: ~
638      • {on_jump}?   (`fun(diagnostic:vim.Diagnostic?, bufnr:integer)`)
639                     Default value of the {on_jump} parameter of
640                     |vim.diagnostic.jump()|.
641      • {severity}?  (`vim.diagnostic.SeverityFilter`) Default value of the
642                     {severity} parameter of |vim.diagnostic.jump()|.
643      • {wrap}?      (`boolean`, default: true) Default value of the {wrap}
644                     parameter of |vim.diagnostic.jump()|.
645
646*vim.diagnostic.Opts.Signs*
647
648    Fields: ~
649      • {linehl}?    (`table<vim.diagnostic.Severity,string>`) A table mapping
650                     |diagnostic-severity| to the highlight group used for the
651                     whole line the sign is placed in.
652      • {numhl}?     (`table<vim.diagnostic.Severity,string>`) A table mapping
653                     |diagnostic-severity| to the highlight group used for the
654                     line number where the sign is placed.
655      • {priority}?  (`integer`, default: `10`) Base priority to use for
656                     signs. When {severity_sort} is used, the priority of a
657                     sign is adjusted based on its severity. Otherwise, all
658                     signs use the same priority.
659      • {severity}?  (`vim.diagnostic.SeverityFilter`) Only show signs for
660                     diagnostics matching the given severity
661                     |diagnostic-severity|
662      • {text}?      (`table<vim.diagnostic.Severity|vim.diagnostic.SeverityName,string>`)
663                     A table mapping |diagnostic-severity| to the sign text to
664                     display in the sign column and statusline. The default is
665                     to use `"E"`, `"W"`, `"I"`, and `"H"` for errors,
666                     warnings, information, and hints, respectively. Example: >lua
667                         vim.diagnostic.config({
668                           signs = { text = { [vim.diagnostic.severity.ERROR] = 'E', ... } }
669                         })
670<
671
672*vim.diagnostic.Opts.Status*
673
674    Fields: ~
675      • {format}?  (`fun(counts:table<vim.diagnostic.Severity,integer>): string`)
676                   Function that accepts a mapping of |diagnostic-severity| to
677                   the number of diagnostics of the corresponding severity
678                   (only those having at least 1 diagnostic) and returns a
679                   'statusline' component. Highlights must be applied by the
680                   `format` function. Example: >lua
681                       local signs = {
682                         [vim.diagnostic.severity.ERROR] = "A",
683                         -- ...
684                       }
685                       local hl_map = {
686                         [vim.diagnostic.severity.ERROR] = 'DiagnosticSignError',
687                         -- ...
688                       }
689                       vim.diagnostic.config({
690                         status = {
691                           format = function(severity_counts)
692                             local items = {}
693                             for severity in ipairs(vim.diagnostic.severity) do
694                               local count = severity_counts[severity] or 0
695                               table.insert(items, ("%%#%s#%s %s"):format(hl_map[severity], signs[severity], count))
696                             end
697                             return table.concat(items, " ")
698                           end
699                         }
700                       })
701<
702
703*vim.diagnostic.Opts.Underline*
704
705    Fields: ~
706      • {severity}?  (`vim.diagnostic.SeverityFilter`) Only underline
707                     diagnostics matching the given severity
708                     |diagnostic-severity|.
709
710*vim.diagnostic.Opts.VirtualLines*
711
712    Fields: ~
713      • {current_line}?  (`boolean`, default: `false`) Only show diagnostics
714                         for the current line. Updated on |CursorHold|, see
715                         'updatetime'.
716      • {format}?        (`fun(diagnostic:vim.Diagnostic): string?`) A
717                         function that takes a diagnostic as input and returns
718                         a string or nil. If the return value is nil, the
719                         diagnostic is not displayed by the handler. Else the
720                         output text is used to display the diagnostic.
721      • {overflow}?      (`'trunc'|'scroll'|'wrap'|'auto'`, default: `auto`)
722                         See `virt_lines_overflow` in
723                         |nvim_buf_set_extmark()|.
724      • {severity}?      (`vim.diagnostic.SeverityFilter`) Only show virtual
725                         lines for diagnostics matching the given severity
726                         |diagnostic-severity|
727
728*vim.diagnostic.Opts.VirtualText*
729
730    Fields: ~
731      • {current_line}?       (`boolean`, default: `nil`) Show or hide
732                              diagnostics based on the current cursor line. If
733                              `true`, only diagnostics on the current cursor
734                              line are shown. If `false`, all diagnostics are
735                              shown except on the current cursor line. If
736                              `nil`, all diagnostics are shown. Updated on
737                              |CursorHold|, see 'updatetime'.
738      • {format}?             (`fun(diagnostic:vim.Diagnostic): string?`) If
739                              not nil, the return value is the text used to
740                              display the diagnostic. Example: >lua
741                                  function(diagnostic)
742                                    if diagnostic.severity == vim.diagnostic.severity.ERROR then
743                                      return string.format("E: %s", diagnostic.message)
744                                    end
745                                    return diagnostic.message
746                                  end
747<
748
749                              If the return value is nil, the diagnostic is
750                              not displayed by the handler.
751      • {hl_mode}?            (`'replace'|'combine'|'blend'`) See
752                              |nvim_buf_set_extmark()|.
753      • {prefix}?             (`string|(fun(diagnostic:vim.Diagnostic,i:integer,total:integer): string)`)
754                              Prepend diagnostic message with prefix. If a
755                              `function`, {i} is the index of the diagnostic
756                              being evaluated, and {total} is the total number
757                              of diagnostics for the line. This can be used to
758                              render diagnostic symbols or error codes.
759      • {severity}?           (`vim.diagnostic.SeverityFilter`) Only show
760                              virtual text for diagnostics matching the given
761                              severity |diagnostic-severity|
762      • {source}?             (`boolean|"if_many"`) Include the diagnostic
763                              source in virtual text. Use `'if_many'` to only
764                              show sources if there is more than one
765                              diagnostic source in the buffer. Otherwise, any
766                              truthy value means to always show the diagnostic
767                              source.
768      • {spacing}?            (`integer`) Amount of empty spaces inserted at
769                              the beginning of the virtual text.
770      • {suffix}?             (`string|(fun(diagnostic:vim.Diagnostic): string)`)
771                              Append diagnostic message with suffix. This can
772                              be used to render an LSP diagnostic error code.
773      • {virt_text}?          (`[string,any][]`) See |nvim_buf_set_extmark()|.
774      • {virt_text_hide}?     (`boolean`) See |nvim_buf_set_extmark()|.
775      • {virt_text_pos}?      (`'eol'|'eol_right_align'|'inline'|'overlay'|'right_align'`)
776                              See |nvim_buf_set_extmark()|.
777      • {virt_text_win_col}?  (`integer`) See |nvim_buf_set_extmark()|.
778
779
780config({opts}, {namespace})                          *vim.diagnostic.config()*
781    Configure diagnostic options globally or for a specific diagnostic
782    namespace.
783
784    Configuration can be specified globally, per-namespace, or ephemerally
785    (i.e. only for a single call to |vim.diagnostic.set()| or
786    |vim.diagnostic.show()|). Ephemeral configuration has highest priority,
787    followed by namespace configuration, and finally global configuration.
788
789    For example, if a user enables virtual text globally with >lua
790        vim.diagnostic.config({ virtual_text = true })
791<
792
793    and a diagnostic producer sets diagnostics with >lua
794        vim.diagnostic.set(ns, 0, diagnostics, { virtual_text = false })
795<
796
797    then virtual text will not be enabled for those diagnostics.
798
799    Parameters: ~
800      • {opts}       (`vim.diagnostic.Opts?`) When omitted or `nil`, retrieve
801                     the current configuration. Otherwise, a configuration
802                     table (see |vim.diagnostic.Opts|).
803      • {namespace}  (`integer?`) Update the options for the given namespace.
804                     When omitted, update the global diagnostic options.
805
806    Overloads: ~
807      • `fun(opts?: nil, namespace?: integer): vim.diagnostic.Opts`
808
809    Return: ~
810        (`vim.diagnostic.Opts?`) Current diagnostic config if {opts} is
811        omitted.
812
813count({buf}, {opts})                                  *vim.diagnostic.count()*
814    Get current diagnostics count.
815
816    Parameters: ~
817      • {buf}   (`integer?`) Buffer number to get diagnostics from. Use 0 for
818                current buffer or nil for all buffers.
819      • {opts}  (`vim.diagnostic.GetOpts?`)
820
821    Return: ~
822        (`table<integer, integer>`) Table with actually present severity
823        values as keys (see |diagnostic-severity|) and integer counts as
824        values.
825
826enable({enable}, {filter})                           *vim.diagnostic.enable()*
827    Enables or disables diagnostics.
828
829    To "toggle", pass the inverse of `is_enabled()`: >lua
830        vim.diagnostic.enable(not vim.diagnostic.is_enabled())
831<
832
833    Parameters: ~
834      • {enable}  (`boolean?`) true/nil to enable, false to disable
835      • {filter}  (`table?`) Optional filters |kwargs|, or `nil` for all.
836                  • {bufnr}? (`integer`) Buffer number, or 0 for current
837                    buffer, or `nil` for all buffers.
838                  • {ns_id}? (`integer`) Diagnostic namespace, or `nil` for
839                    all.
840
841fromqflist({list}, {opts})                       *vim.diagnostic.fromqflist()*
842    Convert a list of quickfix items to a list of diagnostics.
843
844    Parameters: ~
845      • {list}  (`vim.fn.getqflist.ret.item[]`) List of quickfix items from
846                |getqflist()| or |getloclist()|.
847      • {opts}  (`table?`) Configuration table with the following keys:
848                • {merge_lines}? (`boolean`) When true, items with valid=0 are
849                  appended to the previous valid item's message with a
850                  newline. (default: false)
851
852    Return: ~
853        (`vim.Diagnostic[]`)
854
855get({buf}, {opts})                                      *vim.diagnostic.get()*
856    Get current diagnostics.
857
858    Modifying diagnostics in the returned table has no effect. To set
859    diagnostics in a buffer, use |vim.diagnostic.set()|.
860
861    Parameters: ~
862      • {buf}   (`integer?`) Buffer number to get diagnostics from. Use 0 for
863                current buffer or nil for all buffers.
864      • {opts}  (`vim.diagnostic.GetOpts?`)
865
866    Return: ~
867        (`vim.Diagnostic[]`)
868
869get_namespace({namespace})                    *vim.diagnostic.get_namespace()*
870    Get namespace metadata.
871
872    Parameters: ~
873      • {namespace}  (`integer`) Diagnostic namespace
874
875    Return: ~
876        (`vim.diagnostic.NS`) Namespace metadata
877
878get_namespaces()                             *vim.diagnostic.get_namespaces()*
879    Get current diagnostic namespaces.
880
881    Return: ~
882        (`table<integer,vim.diagnostic.NS>`) List of active diagnostic
883        namespaces |vim.diagnostic|.
884
885get_next({opts})                                   *vim.diagnostic.get_next()*
886    Get the next diagnostic closest to the cursor position.
887
888    Parameters: ~
889      • {opts}  (`vim.diagnostic.JumpOpts?`)
890
891    Return: ~
892        (`vim.Diagnostic?`) Next diagnostic
893
894get_prev({opts})                                   *vim.diagnostic.get_prev()*
895    Get the previous diagnostic closest to the cursor position.
896
897    Parameters: ~
898      • {opts}  (`vim.diagnostic.JumpOpts?`)
899
900    Return: ~
901        (`vim.Diagnostic?`) Previous diagnostic
902
903hide({namespace}, {buf})                               *vim.diagnostic.hide()*
904    Hide currently displayed diagnostics.
905
906    This only clears the decorations displayed in the buffer. Diagnostics can
907    be redisplayed with |vim.diagnostic.show()|. To completely remove
908    diagnostics, use |vim.diagnostic.reset()|.
909
910    To hide diagnostics and prevent them from re-displaying, use
911    |vim.diagnostic.enable()|.
912
913    Parameters: ~
914      • {namespace}  (`integer?`) Diagnostic namespace. When omitted, hide
915                     diagnostics from all namespaces.
916      • {buf}        (`integer?`) Buffer number, or 0 for current buffer. When
917                     omitted, hide diagnostics in all buffers.
918
919is_enabled({filter})                             *vim.diagnostic.is_enabled()*
920    Check whether diagnostics are enabled.
921
922    Attributes: ~
923        Since: 0.10.0
924
925    Parameters: ~
926      • {filter}  (`table?`) Optional filters |kwargs|, or `nil` for all.
927                  • {bufnr}? (`integer`) Buffer number, or 0 for current
928                    buffer, or `nil` for all buffers.
929                  • {ns_id}? (`integer`) Diagnostic namespace, or `nil` for
930                    all.
931
932    Return: ~
933        (`boolean`)
934
935jump({opts})                                           *vim.diagnostic.jump()*
936    Move to a diagnostic.
937
938    Parameters: ~
939      • {opts}  (`vim.diagnostic.JumpOpts`)
940
941    Return: ~
942        (`vim.Diagnostic?`) The diagnostic that was moved to.
943
944                                                      *vim.diagnostic.match()*
945match({str}, {pat}, {groups}, {severity_map}, {defaults})
946    Parse a diagnostic from a string.
947
948    For example, consider a line of output from a linter: >
949        WARNING filename:27:3: Variable 'foo' does not exist
950<
951
952    This can be parsed into a |vim.Diagnostic.Set| structure with: >lua
953        local s = "WARNING filename:27:3: Variable 'foo' does not exist"
954        local pattern = "^(%w+) %w+:(%d+):(%d+): (.+)$"
955        local groups = { "severity", "lnum", "col", "message" }
956        vim.diagnostic.match(s, pattern, groups, { WARNING = vim.diagnostic.WARN })
957<
958
959    Parameters: ~
960      • {str}           (`string`) String to parse diagnostics from.
961      • {pat}           (`string`) Lua pattern with capture groups.
962      • {groups}        (`string[]`) List of fields in a |vim.Diagnostic.Set|
963                        structure to associate with captures from {pat}.
964      • {severity_map}  (`table`) A table mapping the severity field from
965                        {groups} with an item from |vim.diagnostic.severity|.
966      • {defaults}      (`table?`) Table of default values for any fields not
967                        listed in {groups}. When omitted, numeric values
968                        default to 0 and "severity" defaults to ERROR.
969
970    Return: ~
971        (`vim.Diagnostic.Set?`) |vim.Diagnostic.Set| structure or `nil` if
972        {pat} fails to match {str}.
973
974open_float({opts})                               *vim.diagnostic.open_float()*
975    Show diagnostics in a floating window.
976
977    Parameters: ~
978      • {opts}  (`vim.diagnostic.Opts.Float?`)
979
980    Return (multiple): ~
981        (`integer?`) float_bufnr
982        (`integer?`) winid
983
984reset({namespace}, {buf})                             *vim.diagnostic.reset()*
985    Remove all diagnostics from the given namespace.
986
987    Unlike |vim.diagnostic.hide()|, this function removes all saved
988    diagnostics. They cannot be redisplayed using |vim.diagnostic.show()|. To
989    simply remove diagnostic decorations in a way that they can be
990    re-displayed, use |vim.diagnostic.hide()|.
991
992    Parameters: ~
993      • {namespace}  (`integer?`) Diagnostic namespace. When omitted, remove
994                     diagnostics from all namespaces.
995      • {buf}        (`integer?`) Remove diagnostics for the given buffer.
996                     When omitted, diagnostics are removed for all buffers.
997
998set({namespace}, {buf}, {diagnostics}, {opts})          *vim.diagnostic.set()*
999    Set diagnostics for the given namespace and buffer.
1000
1001    Parameters: ~
1002      • {namespace}    (`integer`) The diagnostic namespace
1003      • {buf}          (`integer`) Buffer number
1004      • {diagnostics}  (`vim.Diagnostic.Set[]`)
1005      • {opts}         (`vim.diagnostic.Opts?`) Display options to pass to
1006                       |vim.diagnostic.show()|
1007
1008setloclist({opts})                               *vim.diagnostic.setloclist()*
1009    Add buffer diagnostics to the location list.
1010
1011    Parameters: ~
1012      • {opts}  (`table?`) Configuration table with the following keys:
1013                • {format}? (`fun(diagnostic:vim.Diagnostic): string?`) A
1014                  function that takes a diagnostic as input and returns a
1015                  string or nil. If the return value is nil, the diagnostic is
1016                  not displayed in the location list. Else the output text is
1017                  used to display the diagnostic.
1018                • {namespace}? (`integer[]|integer`) Only add diagnostics from
1019                  the given namespace(s).
1020                • {open}? (`boolean`, default: `true`) Open the location list
1021                  after setting.
1022                • {severity}? (`vim.diagnostic.SeverityFilter`) See
1023                  |diagnostic-severity|.
1024                • {title}? (`string`) Title of the location list. Defaults to
1025                  "Diagnostics".
1026                • {winnr}? (`integer`, default: `0`) Window number to set
1027                  location list for.
1028
1029setqflist({opts})                                 *vim.diagnostic.setqflist()*
1030    Add all diagnostics to the quickfix list.
1031
1032    Parameters: ~
1033      • {opts}  (`table?`) Configuration table with the following keys:
1034                • {format}? (`fun(diagnostic:vim.Diagnostic): string?`) A
1035                  function that takes a diagnostic as input and returns a
1036                  string or nil. If the return value is nil, the diagnostic is
1037                  not displayed in the quickfix list. Else the output text is
1038                  used to display the diagnostic.
1039                • {namespace}? (`integer[]|integer`) Only add diagnostics from
1040                  the given namespace(s).
1041                • {open}? (`boolean`, default: `true`) Open quickfix list
1042                  after setting.
1043                • {severity}? (`vim.diagnostic.SeverityFilter`) See
1044                  |diagnostic-severity|.
1045                • {title}? (`string`) Title of quickfix list. Defaults to
1046                  "Diagnostics". If there's already a quickfix list with this
1047                  title, it's updated. If not, a new quickfix list is created.
1048
1049show({namespace}, {buf}, {diagnostics}, {opts})        *vim.diagnostic.show()*
1050    Display diagnostics for the given namespace and buffer.
1051
1052    Parameters: ~
1053      • {namespace}    (`integer?`) Diagnostic namespace. When omitted, show
1054                       diagnostics from all namespaces.
1055      • {buf}          (`integer?`) Buffer number, or 0 for current buffer.
1056                       When omitted, show diagnostics in all buffers.
1057      • {diagnostics}  (`vim.Diagnostic[]?`) The diagnostics to display. When
1058                       omitted, use the saved diagnostics for the given
1059                       namespace and buffer. This can be used to display a
1060                       list of diagnostics without saving them or to display
1061                       only a subset of diagnostics. May not be used when
1062                       {namespace} or {buf} is nil.
1063      • {opts}         (`vim.diagnostic.Opts?`) Display options.
1064
1065status({buf})                                        *vim.diagnostic.status()*
1066    Returns formatted string with diagnostics for the current buffer. The
1067    severities with 0 diagnostics are left out. Example `E:2 W:3 I:4 H:5`
1068
1069    To customise appearance, see |vim.diagnostic.Opts.Status|.
1070
1071    Parameters: ~
1072      • {buf}  (`integer?`) Buffer number to get diagnostics from. Defaults to
1073               0 for the current buffer
1074
1075    Return: ~
1076        (`string`)
1077
1078toqflist({diagnostics})                            *vim.diagnostic.toqflist()*
1079    Convert a list of diagnostics to a list of quickfix items that can be
1080    passed to |setqflist()| or |setloclist()|.
1081
1082    Parameters: ~
1083      • {diagnostics}  (`vim.Diagnostic[]`)
1084
1085    Return: ~
1086        (`table[]`) Quickfix list items |setqflist-what|
1087
1088
1089 vim:tw=78:ts=8:sw=4:sts=4:et:ft=help:norl: