-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
Adds support for workspace/willRenameFiles
#33
Conversation
This commit calls a callback in the `nvim-lsp-file-operations` plugin, if available. <antosha417/nvim-lsp-file-operations#13> The affacted file operations are "rename" and "move-rename".
I have tested this only with rust-analyzer! |
great, thanks! Tested it with tsserver (works), and lua_ls (not supported). Could you do the following to make this properly ready for merging:
|
would |
either that, or maybe change the prompt text of |
I just stumbled upon this on reddit: it appears, it may be LSP-renaming even without |
Oh I like that. That is way simpler than to depend on a plugin. In that case I think there are two approaches:
--stolen from https://github.com/LazyVim/LazyVim/blob/fecc5faca25c209ed62e3658dd63731e26c0c643/lua/lazyvim/util/init.lua#L304
local function on_rename(from, to)
local clients = vim.lsp.get_active_clients()
for _, client in ipairs(clients) do
if client:supports_method("workspace/willRenameFiles") then
local resp = client.request_sync("workspace/willRenameFiles", {
files = {
{
oldUri = vim.uri_from_fname(from),
newUri = vim.uri_from_fname(to),
},
},
}, 1000)
if resp and resp.result ~= nil then
vim.lsp.util.apply_workspace_edit(resp.result, client.offset_encoding)
end
end
end
end
-- pseudo genghis config
local khan = require'genghis'
khan.setup{
...
post_operation = function(file_operation, ...)
if file_operation == 'rename' or file_operation 'move-rename' then
on_rename(...)
end
end,
...
} |
yeah, I think baking it into genghis makes much more sense. No need to burden the user with the need to add boilerplate to their config. |
thx! Could you add some information to the readme on the change? And maybe also post a notification for the user when the LSP-rename is due to an attached LSP supporting it? Then I think we can merge this |
nvim-lsp-file-operations
workspace/willRenameFiles
Also refactors to camelCase names.
Not sure about the wording inside the prompts, but those are easy to change anytime. |
thanks, looks good to me now! Bummer that many LSPs like lua_ls do not support |
hmm, so there were some issues with the renaming-capability-detectin. I fixed them, but just so you are aware of it: Lines 36 to 51 in 68149dd
(also, |
This commit calls a callback in the
nvim-lsp-file-operations
plugin,if available.
antosha417/nvim-lsp-file-operations#13
The affected file operations are "rename" and "move-rename".