summaryrefslogtreecommitdiff
path: root/nvim/lua/config/file-rename.lua
diff options
context:
space:
mode:
Diffstat (limited to 'nvim/lua/config/file-rename.lua')
-rw-r--r--nvim/lua/config/file-rename.lua22
1 files changed, 22 insertions, 0 deletions
diff --git a/nvim/lua/config/file-rename.lua b/nvim/lua/config/file-rename.lua
new file mode 100644
index 0000000..a466568
--- /dev/null
+++ b/nvim/lua/config/file-rename.lua
@@ -0,0 +1,22 @@
+-- Updates references (imports, etc.) when a file or folder is renamed/moved in mini.files
+local function update_references(from, to)
+ local params = { files = { { oldUri = vim.uri_from_fname(from), newUri = vim.uri_from_fname(to) } } }
+ for _, client in ipairs(vim.lsp.get_clients()) do
+ if client:supports_method("workspace/willRenameFiles") then
+ local response = client:request_sync("workspace/willRenameFiles", params, 3000, 0)
+ if response and response.result then
+ vim.lsp.util.apply_workspace_edit(response.result, client.offset_encoding)
+ end
+ end
+ if client:supports_method("workspace/didRenameFiles") then
+ client:notify("workspace/didRenameFiles", params)
+ end
+ end
+end
+
+vim.api.nvim_create_autocmd("User", {
+ pattern = { "MiniFilesActionRename", "MiniFilesActionMove" },
+ callback = function(event)
+ update_references(event.data.from, event.data.to)
+ end,
+})