simrat39 / rust-tools.nvim

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

renaming a module causes an error if a directory with the same name as the module exists #314

Closed Trard closed 1 year ago

Trard commented 1 year ago

When I try to rename a rust module using vim.lsp.buf.rename (in .rs file) I get the following

Error executing vim.schedule lua callback: /usr/share/nvim/runtime/lua/vim/lsp/util.lua:762: Error executing lua: /usr/share/nvim/runtime/lua/vim/lsp/util.lua:763: Vim(write):E502: "instance/instance_builder"
is a directory
stack traceback:
        [C]: in function 'cmd'
        /usr/share/nvim/runtime/lua/vim/lsp/util.lua:763: in function </usr/share/nvim/runtime/lua/vim/lsp/util.lua:762>
        [C]: in function 'nvim_buf_call'
        /usr/share/nvim/runtime/lua/vim/lsp/util.lua:762: in function 'rename'
        /usr/share/nvim/runtime/lua/vim/lsp/util.lua:828: in function 'apply_workspace_edit'
        /usr/share/nvim/runtime/lua/vim/lsp/handlers.lua:279: in function 'handler'
        /usr/share/nvim/runtime/lua/vim/lsp/buf.lua:314: in function 'handler'
        /usr/share/nvim/runtime/lua/vim/lsp.lua:1391: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>
stack traceback:
        [C]: in function 'nvim_buf_call'
        /usr/share/nvim/runtime/lua/vim/lsp/util.lua:762: in function 'rename'
        /usr/share/nvim/runtime/lua/vim/lsp/util.lua:828: in function 'apply_workspace_edit'
        /usr/share/nvim/runtime/lua/vim/lsp/handlers.lua:279: in function 'handler'
        /usr/share/nvim/runtime/lua/vim/lsp/buf.lua:314: in function 'handler'
        /usr/share/nvim/runtime/lua/vim/lsp.lua:1391: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>
Press ENTER or type command to continue
[LSP] Client with id 1 not attached to buffer 4
Press ENTER or type command to continue

Minimal config:

local fn = vim.fn
local packer = require("packer")

packer.startup(function(use)
        use("wbthomason/packer.nvim")
        use("simrat39/rust-tools.nvim")
        use({"neovim/nvim-lspconfig"})
end)

local rt = require("rust-tools")

rt.setup({})

vim.keymap.set("n", "rn", vim.lsp.buf.rename, { noremap = true })

nvim version: NVIM v0.9.0-dev rust-analyzer version: 0.3.1229-standalone

Trard commented 1 year ago

This bug causes only if a directory with the same name as the module exists.

Steps to reproduce bug:

  1. Clone https://github.com/Trard/rust-neovim-314.
  2. Open src/main.rs in neovim.
  3. Try to rename mod bar.
  4. Look at the error.

But if you try to rename mod foo, it will be renamed as expected.

simrat39 commented 1 year ago

Looks like a neovim issue. Does this persist with lspconfig's rust-analyzer config?

Trard commented 1 year ago

Does this persist with lspconfig's rust-analyzer config?

Yes, this persists with lspconfig's rust-analyzer config

Should I open issue in neovim?

simrat39 commented 1 year ago

Does this persist with lspconfig's rust-analyzer config?

Yes, this persists with lspconfig's rust-analyzer config

Should I open issue in neovim?

Yep

Trard commented 1 year ago

https://github.com/neovim/neovim/issues/22147