artemave/workspace-diagnostics.nvim

website github github
lspneovim-0.5diagnostics
stars 113
issues 4
subscribers 4
forks 3
CREATED

2024-02-07

UPDATED

2 days ago


https://github.com/artemave/workspace-diagnostics.nvim/assets/23721/ae32fdc8-a547-4194-ae00-df19c66d2b5f

📋 Installation

wbthomason/packer.nvim

use {"artemave/workspace-diagnostics.nvim"}

junegunn/vim-plug

Plug "artemave/workspace-diagnostics.nvim"

folke/lazy.nvim

require("lazy").setup({"artemave/workspace-diagnostics.nvim"})

⚡️ Usage

Populate workspace diagnostcs when an lsp client is attached:

require('lspconfig').tsserver.setup({
  on_attach = function(client, bufnr)
                ...
                require("workspace-diagnostics").populate_workspace_diagnostics(client, bufnr)
                ...
              end
})

Despite its placement, populate_workspace_diagnostics will actually do the work only once per client.

Alternatively, you can trigger it explicitly via a keybinding. E.g., the following code maps <space>x to populate workspace diagnostics:

vim.api.nvim_set_keymap('n', '<space>x', '', {
  noremap = true,
  callback = function()
    for _, client in ipairs(vim.lsp.buf_get_clients()) do
      require("workspace-diagnostics").populate_workspace_diagnostics(client, 0)
    end
  end
})

Caveat: this only populates diagnostics for the files that share type with the current buffer. E.g., in a rails project, if you run this in a javascript file, you'll get diagnostics for all javascript files, but not ruby files.

⚙ Configuration

You can configure a different function that returns a list of project files (it defaults to the output of git ls-files).

require("workspace-diagnostics").setup({
  workspace_files = function()
    return { 'index.js', 'lib/banana.js' }
  end
})

⌨ Contributing

PRs and issues are always welcome. Make sure to provide as much context as possible when opening one.

To run make lint locally, you'd need to install stylua:

cargo install stylua --features lua52