aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/util.lua
diff options
context:
space:
mode:
authorJaehwang Jung <tomtomjhj@gmail.com>2024-03-02 02:31:54 +0900
committerGitHub <noreply@github.com>2024-03-01 18:31:54 +0100
commitb413f5d048ab8676d5a77d0f2b3c20587a270673 (patch)
treeadb45457aaf72390ce8a15da1ce2c62613966ac5 /runtime/lua/vim/lsp/util.lua
parent5d4e1693cb415e8b76749e833e28f00f14630b87 (diff)
downloadrneovim-b413f5d048ab8676d5a77d0f2b3c20587a270673.tar.gz
rneovim-b413f5d048ab8676d5a77d0f2b3c20587a270673.tar.bz2
rneovim-b413f5d048ab8676d5a77d0f2b3c20587a270673.zip
fix(lsp): rename undofile when renaming (#27684)
Problem: After `rename()`, the undo information for the renamed file(s) are lost. Solution: Rename the undofile as well.
Diffstat (limited to 'runtime/lua/vim/lsp/util.lua')
-rw-r--r--runtime/lua/vim/lsp/util.lua7
1 files changed, 7 insertions, 0 deletions
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua
index d2a5d9a08e..0553d39851 100644
--- a/runtime/lua/vim/lsp/util.lua
+++ b/runtime/lua/vim/lsp/util.lua
@@ -724,6 +724,13 @@ function M.rename(old_fname, new_fname, opts)
local ok, err = os.rename(old_fname_full, new_fname)
assert(ok, err)
+ local old_undofile = vim.fn.undofile(old_fname_full)
+ if uv.fs_stat(old_undofile) ~= nil then
+ local new_undofile = vim.fn.undofile(new_fname)
+ vim.fn.mkdir(assert(vim.fs.dirname(new_undofile)), 'p')
+ os.rename(old_undofile, new_undofile)
+ end
+
if vim.fn.isdirectory(new_fname) == 0 then
local newbuf = vim.fn.bufadd(new_fname)
if win then