From 8addd27504e698da62176824209ae2d3d24247c0 Mon Sep 17 00:00:00 2001 From: Jaehwang Jung Date: Sun, 25 Feb 2024 00:47:34 +0900 Subject: fix(lsp): when renaming directory, check path prefix of buffer names (#27603) For example, when renaming /path/to/dir, buffers like fern://drawer/file:///path/to/dir, /path/to/dir123 should not be matched. --- test/functional/plugin/lsp_spec.lua | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index be9a8342ff..b57fb268e1 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -2515,6 +2515,47 @@ describe('LSP', function() os.remove(new_dir) end) + it('Does not touch buffers that do not match path prefix', function() + local old = tmpname() + local new = tmpname() + os.remove(old) + os.remove(new) + helpers.mkdir_p(old) + + local result = exec_lua( + [[ + local old = select(1, ...) + local new = select(2, ...) + + local old_prefixed = 'explorer://' .. old + local old_suffixed = old .. '.bak' + local new_prefixed = 'explorer://' .. new + local new_suffixed = new .. '.bak' + + local old_prefixed_buf = vim.fn.bufadd(old_prefixed) + local old_suffixed_buf = vim.fn.bufadd(old_suffixed) + local new_prefixed_buf = vim.fn.bufadd(new_prefixed) + local new_suffixed_buf = vim.fn.bufadd(new_suffixed) + + vim.lsp.util.rename(old, new) + + return + vim.api.nvim_buf_is_valid(old_prefixed_buf) and + vim.api.nvim_buf_is_valid(old_suffixed_buf) and + vim.api.nvim_buf_is_valid(new_prefixed_buf) and + vim.api.nvim_buf_is_valid(new_suffixed_buf) and + vim.api.nvim_buf_get_name(old_prefixed_buf) == old_prefixed and + vim.api.nvim_buf_get_name(old_suffixed_buf) == old_suffixed and + vim.api.nvim_buf_get_name(new_prefixed_buf) == new_prefixed and + vim.api.nvim_buf_get_name(new_suffixed_buf) == new_suffixed + ]], + old, + new + ) + eq(true, result) + + os.remove(new) + end) it( 'Does not rename file if target exists and ignoreIfExists is set or overwrite is false', function() -- cgit