Update imports on file rename is not working
Closed this issue ยท 4 comments
I did setup vtsls with neovim and was excited to move from tsserver to LSP close to vscode one. After setup I have a new issue: imports are not updated on file rename. But in LSP capabilities I mentioned the fileOperation capability:
fileOperations: {
didRename: {
filters: [
{
scheme: "file",
pattern: {
glob: "**/*.{ts,cts,mts,tsx,js,cjs,mjs,jsx}",
matches: "file",
},
},
{
scheme: "file",
pattern: {
glob: "**/*",
matches: "folder",
},
},
],
},
},
I use nvim cmp alongside Mason and Mason LSP config. Is this the issue with nvim or vtsls?
Neovim doesn't support workspace/didRenameFiles
notification so additional handling should be done on the client side to make this work. Assuming that you are using a file manager plugin, take a look at my implementation for automatic paths update for reference. It just requires sending the notification including files paths to the server, and most of the file manager plugins expose APIs to subscribe the renaming event. If you are using nvim-tree.lua
, then directly copy and paste the snippet will just work.
I didn't know such scripts exist!
Where did you add it though? I am using lazy.nvim and added it to nvim-tree config option only to get:
Failed to run 'config' for nvim-tree.Lua
...l/share/nvim/lazy/nvim-tree.lua/lua/nvim-tree/events.lua:31: table index is nil
Sorry for my mistake, there is a small typo in the original snippet (haven't found it untill your feedback ๐ ):
api.events.subscribe(api.events.Event.NodeRename
api.events.subscribe(api.events.Event.NodeRenamed
Wow, amazing man! Thank you)
P.S. I think I found small typo in is_sub_path:
local function is_sub_path(path, folder)
path = trim_sep(path)
folder = trim_sep(path) -- should here be folder?
if path == folder then
return true
else
return path:sub(1, #folder + 1) == folder .. path_sep
end
end