【问题标题】:How to apply multiple auto fixes with nvim LSP如何使用 nvim LSP 应用多个自动修复
【发布时间】:2022-08-09 10:18:16
【问题描述】:

在 nvim 中,使用 LSP,我希望能够应用“修复所有相同类型”,类似于在 VSCode 中可以完成的操作(见图)。如何将其添加到 LSP 代码操作中?

编辑:我知道这可以使用 COC 来完成。但我想要它用于 LSP。

    标签: neovim nvim-lspconfig


    【解决方案1】:

    这取决于您使用的语言服务器,在我当前的 NeoVim 配置中,我同时运行 ESLint 和 tsserver,并且在我的项目根目录中使用 ESLint 的默认配置,我得到了这些类型的代码操作。

    假设您使用的是 lspconfig 插件,您需要确保已配置服务器:

    local capabilities = vim.lsp.protocol.make_client_capabilities()
    capabilities.textDocument.completion.completionItem.snippetSupport = true
    require('lspconfig')['tsserver'].setup {
      on_attach = function() end,
      capabilities = capabilities,
    }
    require('lspconfig')['eslint'].setup {
      on_attach = function() end,
      capabilities = capabilities,
    }
    

    然后你可以在 neovim 中运行::lua vim.lsp.buf.code_action() in command mode (n)

    您需要手动安装两个 LSP

    参考:

    注:您可能应该在 on_attach 回调中添加与 LSP 相关的键盘映射

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-08-10
      • 2012-10-08
      • 1970-01-01
      • 2020-08-25
      • 2021-06-11
      • 2017-12-10
      • 2017-03-24
      • 2022-12-08
      相关资源
      最近更新 更多