mirror of
https://github.com/neovim/neovim.git
synced 2024-12-23 20:55:18 -07:00
fix(lsp): remove unnecessary file load/write when renaming (#27621)
Previously rename would unconditionally read the to-be-renamed file from the disk and write it to the disk. This is redundant in some cases If the file is not already loaded, it's not attached to lsp client, so nvim doesn't need to care about this file. If the file is loaded but has no change, it doesn't need to be written.
This commit is contained in:
parent
2f85bbe615
commit
7311958e12
@ -710,11 +710,12 @@ function M.rename(old_fname, new_fname, opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
for _, b in ipairs(oldbufs) do
|
for _, b in ipairs(oldbufs) do
|
||||||
vim.fn.bufload(b)
|
-- There may be pending changes in the buffer
|
||||||
-- The there may be pending changes in the buffer
|
if api.nvim_buf_is_loaded(b) then
|
||||||
api.nvim_buf_call(b, function()
|
api.nvim_buf_call(b, function()
|
||||||
vim.cmd('w!')
|
vim.cmd('update!')
|
||||||
end)
|
end)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local newdir = assert(vim.fs.dirname(new_fname))
|
local newdir = assert(vim.fs.dirname(new_fname))
|
||||||
|
@ -2611,7 +2611,7 @@ describe('LSP', function()
|
|||||||
|
|
||||||
eq(false, exec_lua('return vim.uv.fs_stat(...) ~= nil', old))
|
eq(false, exec_lua('return vim.uv.fs_stat(...) ~= nil', old))
|
||||||
eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', new))
|
eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', new))
|
||||||
eq('Old file\n', read_file(new))
|
eq('Old file', read_file(new))
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user