-
-
Notifications
You must be signed in to change notification settings - Fork 625
feat(event): add will rename node event. #1821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(event): add will rename node event. #1821
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works.
Not quite sure what the use cases will be...
@alex-courtis, so one of the possible use-cases is the following: local api = require('nvim-tree.api')
local Event = api.events.Event
function _G.dump(...)
local objects = vim.tbl_map(vim.inspect, { ... })
print(unpack(objects))
return ...
end
dump("Loaded will_rename_listener")
local function getWorkspaceEdit(client, data)
local will_rename_params = {
files = {
{
newUri = "file://" .. data.new_name,
oldUri = "file://" .. data.old_name
}
}
}
local resp = client.request_sync("workspace/willRenameFiles", will_rename_params, 1000)
return resp.result
end
api.events.subscribe(Event.WillRenameNode, function(data)
dump("Got will_rename_event")
dump(data)
for _, client in pairs(vim.lsp.get_active_clients()) do
if client.name == "metals" then
local edit = getWorkspaceEdit(client, data)
dump("Got workspace edit")
dump(edit)
vim.lsp.util.apply_workspace_edit(edit, client.offset_encoding)
end
end
end) Now when I move files around in I think that rust language server also supports |
@antosha417 Could you maybe add that to wiki? Seems like pretty significant functionality that users might want to configure. This is pretty neat! |
@gegoune I'll explore this a bit more with couple of other language servers and add this to wiki. I'm also very excited about it. |
Oh that is nice... I can see instances where that would be useful. Wiki: yes please! |
@gegoune, @alex-courtis I think there might be some corner cases which I don't know about. So I thought that wiki is not a great place to maintain that peace of code. Will write about that extension in the wiki though. |
Perhaps it deserves its own |
Done: https://github.com/nvim-tree/nvim-tree.lua/wiki/Extensions I shall enjoy using |
lsp-file-operations runs fine when its setup is called before nvim-tree's. Proves that the event system is working well :) |
Renamed wiki to https://github.com/nvim-tree/nvim-tree.lua/wiki/Extension-Plugins and added mini.base16 |
Hey!
Some language servers support workspace/willRenameFiles request. It is used in order to automatically fix imports.
Currently neovim does not support it. So plugins must be used if one wants to use this feature. Here is an open issue in neovim repo.
Since I use
nvim-tree.lua
for all file manipulations I thought it would be cool to addWillRenameNode
event and do workspace/willRenameFiles request in the handler.