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.
This commit is contained in:
Jaehwang Jung
2024-02-25 00:47:34 +09:00
committed by GitHub
parent 04f723f1a5
commit 8addd27504
3 changed files with 85 additions and 15 deletions

View File

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