aboutsummaryrefslogtreecommitdiff
path: root/test/functional/plugin/lsp_spec.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 /test/functional/plugin/lsp_spec.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 'test/functional/plugin/lsp_spec.lua')
-rw-r--r--test/functional/plugin/lsp_spec.lua52
1 files changed, 52 insertions, 0 deletions
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua
index 0fdcd0dd1d..af31d9ccae 100644
--- a/test/functional/plugin/lsp_spec.lua
+++ b/test/functional/plugin/lsp_spec.lua
@@ -2593,6 +2593,58 @@ describe('LSP', function()
eq('New file', read_file(new))
end
)
+ it('Maintains undo information for loaded buffer', function()
+ local old = tmpname()
+ write_file(old, 'line')
+ local new = tmpname()
+ os.remove(new)
+
+ local undo_kept = exec_lua(
+ [[
+ local old = select(1, ...)
+ local new = select(2, ...)
+ vim.opt.undofile = true
+ vim.cmd.edit(old)
+ vim.cmd.normal('dd')
+ vim.cmd.write()
+ local undotree = vim.fn.undotree()
+ vim.lsp.util.rename(old, new)
+ return vim.deep_equal(undotree, vim.fn.undotree())
+ ]],
+ old,
+ new
+ )
+ eq(false, exec_lua('return vim.uv.fs_stat(...) ~= nil', old))
+ eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', new))
+ eq(true, undo_kept)
+ end)
+ it('Maintains undo information for unloaded buffer', function()
+ local old = tmpname()
+ write_file(old, 'line')
+ local new = tmpname()
+ os.remove(new)
+
+ local undo_kept = exec_lua(
+ [[
+ local old = select(1, ...)
+ local new = select(2, ...)
+ vim.opt.undofile = true
+ vim.cmd.split(old)
+ vim.cmd.normal('dd')
+ vim.cmd.write()
+ local undotree = vim.fn.undotree()
+ vim.cmd.bdelete()
+ vim.lsp.util.rename(old, new)
+ vim.cmd.edit(new)
+ return vim.deep_equal(undotree, vim.fn.undotree())
+ ]],
+ old,
+ new
+ )
+ eq(false, exec_lua('return vim.uv.fs_stat(...) ~= nil', old))
+ eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', new))
+ eq(true, undo_kept)
+ end)
it('Does override target if overwrite is true', function()
local old = tmpname()
write_file(old, 'Old file')