mirror of
https://github.com/neovim/neovim.git
synced 2026-07-10 03:19:44 +00:00
fix(lsp): check window is still valid after async request #39396
Problem: Since `foldclose` is async, it must wait for the request to return before actually executing, at which point the original window may no longer be valid. Solution: Check whether the window is valid before actually performing `foldclose`.
This commit is contained in:
@@ -331,8 +331,9 @@ function M.foldclose(kind, winid)
|
||||
local params = { textDocument = util.make_text_document_params(bufnr) }
|
||||
vim.lsp.buf_request_all(bufnr, 'textDocument/foldingRange', params, function(...)
|
||||
state:multi_handler(...)
|
||||
-- Ensure this buffer stays as the current buffer after the async request
|
||||
if api.nvim_win_get_buf(winid) == bufnr then
|
||||
-- Ensure this window is still valid and buffer stays as the current buffer
|
||||
-- after the async request.
|
||||
if api.nvim_win_is_valid(winid) and api.nvim_win_get_buf(winid) == bufnr then
|
||||
state:foldclose(kind, winid)
|
||||
end
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user