From 4bbeb37a18b02fc0c1bb5050dce4358b51583968 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 29 May 2024 14:19:03 +0200 Subject: [PATCH] fix(lsp): fix LazyVim's `on_file_rename` to work according to the lsp spec --- lua/lazyvim/plugins/lsp/init.lua | 9 ++++++++- lua/lazyvim/util/lsp.lua | 18 +++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lua/lazyvim/plugins/lsp/init.lua b/lua/lazyvim/plugins/lsp/init.lua index b183464e..105e7108 100644 --- a/lua/lazyvim/plugins/lsp/init.lua +++ b/lua/lazyvim/plugins/lsp/init.lua @@ -53,7 +53,14 @@ return { enabled = true, }, -- add any global capabilities here - capabilities = {}, + capabilities = { + workspace = { + fileOperations = { + didRename = true, + willRename = true, + }, + }, + }, -- options for vim.lsp.buf.format -- `bufnr` and `filter` is handled by the LazyVim formatter, -- but can be also overridden when specified diff --git a/lua/lazyvim/util/lsp.lua b/lua/lazyvim/util/lsp.lua index adc1be0d..86e14748 100644 --- a/lua/lazyvim/util/lsp.lua +++ b/lua/lazyvim/util/lsp.lua @@ -120,22 +120,22 @@ end ---@param from string ---@param to string 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() for _, client in ipairs(clients) do if client.supports_method("workspace/willRenameFiles") then - ---@diagnostic disable-next-line: invisible - local resp = client.request_sync("workspace/willRenameFiles", { - files = { - { - oldUri = vim.uri_from_fname(from), - newUri = vim.uri_from_fname(to), - }, - }, - }, 1000, 0) + local resp = client.request_sync("workspace/willRenameFiles", changes, 1000, 0) if resp and resp.result ~= nil then vim.lsp.util.apply_workspace_edit(resp.result, client.offset_encoding) end end + if client.supports_method("workspace/didRenameFiles") then + client.notify("workspace/didRenameFiles", changes) + end end end