Skip to content

amadanmath/diag_ignore.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

diag_ignore.nvim

diag_ignore.nvim automates inserting of annotations to disable diagnostic checks in a line of code. Upon triggering the diag_ignore mapping, the user is presented with all the diagnostic messages on the current line. If the user selects a diagnostic code, the code will be ignored on the current line.

Currently supported languages are Lua (lua_ls) and Python (basedpyright, pyright).

Use your favourite plugin manager to install diag_ignore.nvim. For example, a minimal plugin spec with Lazy.nvim:

    {
      "amadanmath/diag_ignore.nvim",
      keys = {
        { '<Leader>ci', '<Plug>(diag_ignore)', mode = 'n', desc = 'Diagnostic: ignore' },
      },
      opts = {},
    }

The default options are:

    opts = {
      ignores = {
        python = { 'endline',  ' # pyright: ignore[', ']' },
        lua =    { 'prevline', '---@diagnostic disable-next-line: ' },
      },
    },

The ignores option lists the supported filetypes. Each value is a table:

    [filetype] = { type, prefix, suffix, joiner, [options] }

If suffix is nil, the default is '' (empty string). If joiner is nil, the default is ', ' (comma and space).

If type is 'endline', the annotation will be appended to the current line. For example, in Python, invoking diag_ignore.nvim on

    1

will result in

    1 # pyright: ignore[reportUnusedExpression]

If type is 'prevline', the annotation will be inserted on the previous line. For example, in Lua, invoking diag_ignore.nvim on

    1

will result in

    ---@diagnostic disable-next-line: exp-in-action
    1

Optional key-value fields can be specified, too. Currently only one is supported: code, specifying where the diagnostic code can be found. By default, code = 'code', which means the contents of diagnostic.code will be used in the annotation. Some diagnostic sources use a different field (e.g. field = 'source' may be necessary). For more advanced analysis, code can be a function taking the diagnostic object as the sole argument, and returning a string containing the code to be used in the annotation.

If an annotation already exists and an additional diagnostic code is selected, the code will be inserted into the existing annotation, separated from the existing codes by joiner.

The default Python config is based on pyright/basedpyright. If you are using mypy, you will have to change the Python config as follows:

    python = { 'endline',  ' # type: ignore[', ']' },

About

NeoVim plugin to automate adding annotations to disable diagnostic messages on the current line

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages