neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 7311958e1238559db7a0b1f490f15f618f51af06
parent 2f85bbe61513d12c746641fed6ad07559bd95719
Author: Jaehwang Jung <tomtomjhj@gmail.com>
Date:   Thu, 29 Feb 2024 01:32:25 +0900

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.

Diffstat:
Mruntime/lua/vim/lsp/util.lua | 11++++++-----
Mtest/functional/plugin/lsp_spec.lua | 2+-
2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua @@ -710,11 +710,12 @@ function M.rename(old_fname, new_fname, opts) end for _, b in ipairs(oldbufs) do - vim.fn.bufload(b) - -- The there may be pending changes in the buffer - api.nvim_buf_call(b, function() - vim.cmd('w!') - end) + -- There may be pending changes in the buffer + if api.nvim_buf_is_loaded(b) then + api.nvim_buf_call(b, function() + vim.cmd('update!') + end) + end end local newdir = assert(vim.fs.dirname(new_fname)) diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua @@ -2611,7 +2611,7 @@ describe('LSP', function() eq(false, exec_lua('return vim.uv.fs_stat(...) ~= nil', old)) 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)