mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-24 17:58:51 +02:00
fix(lsp): fix LazyVim's on_file_rename
to work according to the lsp spec
This commit is contained in:
parent
54d687383d
commit
4bbeb37a18
2 changed files with 17 additions and 10 deletions
|
@ -53,7 +53,14 @@ return {
|
||||||
enabled = true,
|
enabled = true,
|
||||||
},
|
},
|
||||||
-- add any global capabilities here
|
-- add any global capabilities here
|
||||||
capabilities = {},
|
capabilities = {
|
||||||
|
workspace = {
|
||||||
|
fileOperations = {
|
||||||
|
didRename = true,
|
||||||
|
willRename = true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
-- options for vim.lsp.buf.format
|
-- options for vim.lsp.buf.format
|
||||||
-- `bufnr` and `filter` is handled by the LazyVim formatter,
|
-- `bufnr` and `filter` is handled by the LazyVim formatter,
|
||||||
-- but can be also overridden when specified
|
-- but can be also overridden when specified
|
||||||
|
|
|
@ -120,22 +120,22 @@ end
|
||||||
---@param from string
|
---@param from string
|
||||||
---@param to string
|
---@param to string
|
||||||
function M.on_rename(from, to)
|
function M.on_rename(from, to)
|
||||||
|
local changes = { files = { {
|
||||||
|
oldUri = vim.uri_from_fname(from),
|
||||||
|
newUri = vim.uri_from_fname(to),
|
||||||
|
} } }
|
||||||
|
|
||||||
local clients = M.get_clients()
|
local clients = M.get_clients()
|
||||||
for _, client in ipairs(clients) do
|
for _, client in ipairs(clients) do
|
||||||
if client.supports_method("workspace/willRenameFiles") then
|
if client.supports_method("workspace/willRenameFiles") then
|
||||||
---@diagnostic disable-next-line: invisible
|
local resp = client.request_sync("workspace/willRenameFiles", changes, 1000, 0)
|
||||||
local resp = client.request_sync("workspace/willRenameFiles", {
|
|
||||||
files = {
|
|
||||||
{
|
|
||||||
oldUri = vim.uri_from_fname(from),
|
|
||||||
newUri = vim.uri_from_fname(to),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}, 1000, 0)
|
|
||||||
if resp and resp.result ~= nil then
|
if resp and resp.result ~= nil then
|
||||||
vim.lsp.util.apply_workspace_edit(resp.result, client.offset_encoding)
|
vim.lsp.util.apply_workspace_edit(resp.result, client.offset_encoding)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if client.supports_method("workspace/didRenameFiles") then
|
||||||
|
client.notify("workspace/didRenameFiles", changes)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue