neovim

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

commit fed9069b8da123ded62fb8b32e05ed738a0613ff
parent 0412527a407885c01e33068dacd8d6e39fb4dd55
Author: Yi Ming <ofseed@foxmail.com>
Date:   Thu, 22 May 2025 18:16:28 +0800

fix(lsp): avoid `foldclose()` after current window-buffer changed #33901

Problem:
Because the buffer in the window may change before the request is completed, foldclose() might be executed on the wrong buffer.

Solution:
Avoid that.
Diffstat:
Mruntime/lua/vim/lsp/_folding_range.lua | 5++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/runtime/lua/vim/lsp/_folding_range.lua b/runtime/lua/vim/lsp/_folding_range.lua @@ -345,7 +345,10 @@ function M.foldclose(kind, winid) local params = { textDocument = util.make_text_document_params(bufnr) } vim.lsp.buf_request_all(bufnr, ms.textDocument_foldingRange, params, function(...) multi_handler(...) - foldclose(kind, winid) + -- Ensure this buffer stays as the current buffer after the async request + if api.nvim_win_get_buf(winid) == bufnr then + foldclose(kind, winid) + end end) end