summaryrefslogtreecommitdiff
path: root/nvim
diff options
context:
space:
mode:
Diffstat (limited to 'nvim')
-rw-r--r--nvim/lua/config/file-rename.lua17
1 files changed, 17 insertions, 0 deletions
diff --git a/nvim/lua/config/file-rename.lua b/nvim/lua/config/file-rename.lua
index a466568..0d56e73 100644
--- a/nvim/lua/config/file-rename.lua
+++ b/nvim/lua/config/file-rename.lua
@@ -1,3 +1,19 @@
+-- Saves the files changed by a workspace edit. Only those, not all buffers like :wall would
+local function save_edited_files(edit)
+ local uris = vim.tbl_keys(edit.changes or {})
+ for _, change in ipairs(edit.documentChanges or {}) do
+ table.insert(uris, change.textDocument and change.textDocument.uri or change.uri)
+ end
+ for _, uri in ipairs(uris) do
+ local buf = vim.uri_to_bufnr(uri)
+ if vim.api.nvim_buf_is_loaded(buf) and vim.bo[buf].modified then
+ vim.api.nvim_buf_call(buf, function()
+ vim.cmd("silent update")
+ end)
+ end
+ end
+end
+
-- 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) } } }
@@ -6,6 +22,7 @@ local function update_references(from, to)
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)
+ save_edited_files(response.result)
end
end
if client:supports_method("workspace/didRenameFiles") then