Skip to content
项目

artemave/workspace-diagnostics.nvim

在 GitHub 查看

关于

为项目中的 _所有_ 文件生成诊断信息,而不只是已打开的文件。

开发工具

这些数字如何统计

实测星标增长

24小时
0
7天
0
15天
+1
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

workspace-diagnostics.nvim

Populates project-wide lsp diagnostcs, regardless of what files are opened.

This post goes into details of lsp diagnostics and how this plugin works.

Demo

Here you can see that even though a single file gets opened, the diagnostics are populated for other files as well.

📋 Installation

Package manager Snippet

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:

vim.lsp.config('*', {
  on_attach = function(client, bufnr)
                -- some clients support workspace diagnostics natively
                if client:supports_method("workspace/diagnostic", bufnr) then
                  vim.lsp.buf.workspace_diagnostics({ client_id = client.id })
                else
                  require("workspace-diagnostics").populate_workspace_diagnostics(client, bufnr)
                end
              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
})

Some lsp clients do not advertise filetypes they cover, which makes it impossible for this plugin to select relevant project files. In this case, you'll see a warning, and you'll need to explicitly add filetypes when setting up the client. E.g.:

require("roslyn").setup({
  config = {
    filetypes = { 'cs' },
  },
})

⌨ 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

探索相关项目

加载中…