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.
This commit is contained in:
Jaehwang Jung
2024-03-02 02:31:54 +09:00
committed by GitHub
parent 5d4e1693cb
commit b413f5d048
2 changed files with 59 additions and 0 deletions

View File

@@ -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