aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim
diff options
context:
space:
mode:
authorJaehwang Jung <tomtomjhj@gmail.com>2024-02-29 01:32:25 +0900
committerGitHub <noreply@github.com>2024-02-28 17:32:25 +0100
commit7311958e1238559db7a0b1f490f15f618f51af06 (patch)
treec4710d1dff4791cd4aba0ffe3560fe5b7f01b205 /runtime/lua/vim
parent2f85bbe61513d12c746641fed6ad07559bd95719 (diff)
downloadrneovim-7311958e1238559db7a0b1f490f15f618f51af06.tar.gz
rneovim-7311958e1238559db7a0b1f490f15f618f51af06.tar.bz2
rneovim-7311958e1238559db7a0b1f490f15f618f51af06.zip
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 (limited to 'runtime/lua/vim')
-rw-r--r--runtime/lua/vim/lsp/util.lua11
1 files changed, 6 insertions, 5 deletions
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua
index 3973e606f8..d2a5d9a08e 100644
--- 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))