mirror of
https://github.com/neovim/neovim.git
synced 2024-09-17 20:58:20 -04:00
fix(lsp): rename: load and list new buffer if attached to window (#27408)
This commit is contained in:
parent
a376d979bd
commit
d09957e0a0
@ -702,6 +702,8 @@ function M.rename(old_fname, new_fname, opts)
|
|||||||
if vim.fn.isdirectory(new_fname) == 0 then
|
if vim.fn.isdirectory(new_fname) == 0 then
|
||||||
local newbuf = vim.fn.bufadd(new_fname)
|
local newbuf = vim.fn.bufadd(new_fname)
|
||||||
if win then
|
if win then
|
||||||
|
vim.fn.bufload(newbuf)
|
||||||
|
vim.bo[newbuf].buflisted = true
|
||||||
api.nvim_win_set_buf(win, newbuf)
|
api.nvim_win_set_buf(win, newbuf)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2419,6 +2419,68 @@ describe('LSP', function()
|
|||||||
eq(0, lines)
|
eq(0, lines)
|
||||||
os.remove(new)
|
os.remove(new)
|
||||||
end)
|
end)
|
||||||
|
it('new buffer remains unlisted and unloaded if the old was not in window before', function()
|
||||||
|
local old = tmpname()
|
||||||
|
write_file(old, 'Test content')
|
||||||
|
local new = tmpname()
|
||||||
|
os.remove(new) -- only reserve the name, file must not exist for the test scenario
|
||||||
|
local actual = exec_lua(
|
||||||
|
[[
|
||||||
|
local old = select(1, ...)
|
||||||
|
local oldbufnr = vim.fn.bufadd(old)
|
||||||
|
local new = select(2, ...)
|
||||||
|
local newbufnr = vim.fn.bufadd(new)
|
||||||
|
vim.lsp.util.rename(old, new)
|
||||||
|
return {
|
||||||
|
buflisted = vim.bo[newbufnr].buflisted,
|
||||||
|
bufloaded = vim.api.nvim_buf_is_loaded(newbufnr)
|
||||||
|
}
|
||||||
|
]],
|
||||||
|
old,
|
||||||
|
new
|
||||||
|
)
|
||||||
|
|
||||||
|
local expected = {
|
||||||
|
buflisted = false,
|
||||||
|
bufloaded = false,
|
||||||
|
}
|
||||||
|
|
||||||
|
eq(expected, actual)
|
||||||
|
|
||||||
|
os.remove(new)
|
||||||
|
end)
|
||||||
|
it('new buffer is listed and loaded if the old was in window before', function()
|
||||||
|
local old = tmpname()
|
||||||
|
write_file(old, 'Test content')
|
||||||
|
local new = tmpname()
|
||||||
|
os.remove(new) -- only reserve the name, file must not exist for the test scenario
|
||||||
|
local actual = exec_lua(
|
||||||
|
[[
|
||||||
|
local win = vim.api.nvim_get_current_win()
|
||||||
|
local old = select(1, ...)
|
||||||
|
local oldbufnr = vim.fn.bufadd(old)
|
||||||
|
vim.api.nvim_win_set_buf(win, oldbufnr)
|
||||||
|
local new = select(2, ...)
|
||||||
|
vim.lsp.util.rename(old, new)
|
||||||
|
local newbufnr = vim.fn.bufadd(new)
|
||||||
|
return {
|
||||||
|
buflisted = vim.bo[newbufnr].buflisted,
|
||||||
|
bufloaded = vim.api.nvim_buf_is_loaded(newbufnr)
|
||||||
|
}
|
||||||
|
]],
|
||||||
|
old,
|
||||||
|
new
|
||||||
|
)
|
||||||
|
|
||||||
|
local expected = {
|
||||||
|
buflisted = true,
|
||||||
|
bufloaded = true,
|
||||||
|
}
|
||||||
|
|
||||||
|
eq(expected, actual)
|
||||||
|
|
||||||
|
os.remove(new)
|
||||||
|
end)
|
||||||
it('Can rename a directory', function()
|
it('Can rename a directory', function()
|
||||||
-- only reserve the name, file must not exist for the test scenario
|
-- only reserve the name, file must not exist for the test scenario
|
||||||
local old_dir = tmpname()
|
local old_dir = tmpname()
|
||||||
|
Loading…
Reference in New Issue
Block a user