simrat39 / rust-tools.nvim

Tools for better development in rust using neovim's builtin lsp
MIT License
2.17k stars 160 forks source link

duplicate diagnostic item error #394

Open dvic opened 1 year ago

dvic commented 1 year ago

Does anyone encounter the following issue when opening a file from the standard library:

I asked also on rust-analyzer https://github.com/rust-lang/rust-analyzer/discussions/15041 and someone suggested that it might be because the std lib is loaded as a workspace through the lsp.

I'm using lazyvim with the following setup:

return {
  {
    "neovim/nvim-lspconfig",
    opts = {
      servers = {
        rust_analyzer = {},
      },
    },
    setup = {
      rust_analyzer = function(_, _)
        return true
      end,
    },
  },
  {
    "simrat39/rust-tools.nvim",
    dependencies = "neovim/nvim-lspconfig",
    config = function()
      local rt = require("rust-tools")

      rt.setup({
        server = {
          on_attach = require("lazyvim.util").on_attach(function(_, bufnr)
            -- Hover actions
            vim.keymap.set("n", "K", rt.hover_actions.hover_actions, { buffer = bufnr, desc = "Hover" })
            -- Code action groups
            vim.keymap.set(
              "n",
              "<Leader>ca",
              rt.code_action_group.code_action_group,
              { buffer = bufnr, desc = "Code Action" }
            )
          end),
        },
      })
    end,
  },
}
dvic commented 1 year ago

I think I found a clue in the nvim-lspconfig repo: https://github.com/neovim/nvim-lspconfig/blob/5da57456597ac2f25f20d6ecfae7b7c9cbd01fc6/lua/lspconfig/server_configurations/rust_analyzer.lua#L41-L44

It looks like there is custom logic for reusing an instance...

DriedYellowPeach commented 8 months ago

I have the same issue, is there any solution? set reuse_active to avoid booting the second instance?