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.
This commit is contained in:
Yi Ming
2025-05-22 18:16:28 +08:00
committed by GitHub
parent 0412527a40
commit fed9069b8d

View File

@@ -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