MaskRay / ccls

C/C++/ObjC language server supporting cross references, hierarchies, completion and semantic highlighting
Apache License 2.0
3.73k stars 254 forks source link

How to suppress error report for unused function or variable? #869

Open harvey-wei opened 2 years ago

harvey-wei commented 2 years ago

Here are some things you should try before filing a bug report:

If none of those help, remove this section and fill out the four sections in the template below.


Observed behavior

Describe what happened. Any aids you can include (that you think could be relevant) are a tremendous help.

Expected behavior

Describe what you expected to happen.

Steps to reproduce

  1. Select these example steps,
  2. Delete them,
  3. And replace them with precise steps to reproduce your issue.

System information

MarcelRobitaille commented 10 months ago

If you use vim, you can filter them from vim like this:

function filter_diagnostics_pyright(diagnostic)
    -- Allow kwargs to be unused, sometimes you want many functions to take the
    -- same arguments but you don't use all the arguments in all the functions,
    -- so kwargs is used to suck up all the extras
    if diagnostic.message == '"args" is not accessed' or
            diagnostic.message == '"kwargs" is not accessed' then
        return false
    end

    -- Allow variables starting with an underscore
    if string.match(diagnostic.message, '"_.+" is not accessed') then
        return false
    end

    return true
end

function filter_diagnostics(diagnostic)
    if diagnostic.source == "Pyright" then
        return filter_diagnostics_pyright(diagnostic)
    end

    if diagnostic.source == "latex-build" then
        return filter_diagnostics_texlab(diagnostic)
    end

    return true
end

function custom_on_publish_diagnostics(a, params, client_id, c, config)
    params.diagnostics = vim.tbl_filter(filter_diagnostics, params.diagnostics)
    vim.lsp.diagnostic.on_publish_diagnostics(a, params, client_id, c, config)
end

vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
    custom_on_publish_diagnostics, {})

This is for Python, but you get the idea.