Home Explore Blog CI



neovim

6th chunk of `runtime/doc/diagnostic.txt`
30b2237c6636d44faefe2a6ca159906bfec528ab97f57ebe0000000100000fc6
 Example: >lua

    -- Highlight entire line for errors
    -- Highlight the line number for warnings
    vim.diagnostic.config({
        signs = {
            text = {
                [vim.diagnostic.severity.ERROR] = '',
                [vim.diagnostic.severity.WARN] = '',
            },
            linehl = {
                [vim.diagnostic.severity.ERROR] = 'ErrorMsg',
            },
            numhl = {
                [vim.diagnostic.severity.WARN] = 'WarningMsg',
            },
        },
    })

When the "severity_sort" option is set (see |vim.diagnostic.config()|) the
priority of each sign depends on the severity of the associated diagnostic.
Otherwise, all signs have the same priority (the value of the "priority"
option in the "signs" table of |vim.diagnostic.config()| or 10 if unset).

==============================================================================
EVENTS                                                  *diagnostic-events*

                                                        *DiagnosticChanged*
DiagnosticChanged       After diagnostics have changed. When used from Lua,
                        the new diagnostics are passed to the autocmd
                        callback in the "data" table. Triggered per buffer.

Example: >lua

    vim.api.nvim_create_autocmd('DiagnosticChanged', {
      callback = function(args)
        local diagnostics = args.data.diagnostics
        vim.print(diagnostics)
      end,
    })
<
==============================================================================
Lua module: vim.diagnostic                                    *diagnostic-api*

*vim.Diagnostic*
    Extends: |vim.Diagnostic.Set|

                                                        *diagnostic-structure*

    Diagnostics use the same indexing as the rest of the Nvim API (i.e.
    0-based rows and columns). |api-indexing|

    Fields: ~
      • {bufnr}       (`integer`) Buffer number
      • {end_lnum}    (`integer`) The final line of the diagnostic (0-indexed)
      • {col}         (`integer`) The starting column of the diagnostic
                      (0-indexed)
      • {end_col}     (`integer`) The final column of the diagnostic
                      (0-indexed)
      • {severity}    (`vim.diagnostic.Severity`) The severity of the
                      diagnostic |vim.diagnostic.severity|
      • {namespace}?  (`integer`)

*vim.Diagnostic.Set*
    Diagnostics use the same indexing as the rest of the Nvim API (i.e.
    0-based rows and columns). |api-indexing|

    Fields: ~
      • {lnum}        (`integer`) The starting line of the diagnostic
                      (0-indexed)
      • {col}?        (`integer`, default: `0`) The starting column of the
                      diagnostic (0-indexed)
      • {end_lnum}?   (`integer`, default: `lnum`) The final line of the
                      diagnostic (0-indexed)
      • {end_col}?    (`integer`, default: `col`) The final column of the
                      diagnostic (0-indexed)
      • {severity}?   (`vim.diagnostic.Severity`, default: `vim.diagnostic.severity.ERROR`)
                      The severity of the diagnostic |vim.diagnostic.severity|
      • {message}     (`string`) The diagnostic text
      • {source}?     (`string`) The source of the diagnostic
      • {code}?       (`string|integer`) The diagnostic code
      • {user_data}?  (`any`) arbitrary data plugins can add

*vim.diagnostic.GetOpts*
    A table with the following keys:

    Fields: ~
      • {namespace}?  (`integer[]|integer`) Limit diagnostics to one or more
                      namespaces.
      • {lnum}?       (`integer`) Limit diagnostics to those spanning the
                      specified line number.
      • {severity}?   (`vim.diagnostic.SeverityFilter`) See
                      |diagnostic-severity|.
      • {enabled}?    (`boolean`, default: `nil`) Limit diagnostics to only
                      enabled or disabled. If nil, enablement is ignored. See
                   

Title: Diagnostic Events, API, and Data Structures in Neovim
Summary
This section describes the `DiagnosticChanged` event triggered after diagnostics change, providing an example of how to access the new diagnostics within the callback function. It then introduces the `vim.diagnostic` Lua module, detailing the structure of `vim.Diagnostic` and `vim.Diagnostic.Set` objects, which are used to represent and configure diagnostics. The section specifies the fields including line numbers, columns, severity, message, source, code, and user data, all using 0-based indexing. Lastly, it describes `vim.diagnostic.GetOpts`, used to filter diagnostics based on namespace, line number, severity and enablement.