From d5dbfc4512f2a9f176ae06136ca08cba9f010083 Mon Sep 17 00:00:00 2001 From: Skladnayazebra Date: Fri, 6 Nov 2026 17:02:20 +0100 Subject: nvim: save files with renamed imports --- nvim/lua/config/file-rename.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'nvim') 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 -- cgit v1.3.1