mirror of
https://github.com/neovim/neovim.git
synced 2025-10-21 09:12:07 +00:00
fix(lsp): on detach, cancel pending foldingRange requests #31509
Problem: 1. Open a relatively large file (so the server needs some time to process the request). 2. Then immediately execute `:bdelete`. 3. Once the request is completed, the handler will obtain the bufstate of a buffer already unloaded. Error executing vim.schedule lua callback: ...7841_1/share/nvim/runtime/lua/vim/lsp/_folding_range.lua:119: assertion failed! stack traceback: [C]: in function 'assert' ...7841_1/share/nvim/runtime/lua/vim/lsp/_folding_range.lua:119: in function 'multi_handler' ...7841_1/share/nvim/runtime/lua/vim/lsp/_folding_range.lua:140: in function 'handler' ...HEAD-c137841_1/share/nvim/runtime/lua/vim/lsp/client.lua:669: in function '' vim/_editor.lua: in function <vim/_editor.lua:0> Solution: On detach, cancel all pending textDocument_foldingRange requests.
This commit is contained in:
@@ -197,6 +197,11 @@ local function setup(bufnr)
|
||||
-- `on_detach` also runs on buffer reload (`:e`).
|
||||
-- Ensure `bufstate` and hooks are cleared to avoid duplication or leftover states.
|
||||
on_detach = function()
|
||||
util._cancel_requests({
|
||||
bufnr = bufnr,
|
||||
method = ms.textDocument_foldingRange,
|
||||
type = 'pending',
|
||||
})
|
||||
bufstates[bufnr] = nil
|
||||
api.nvim_clear_autocmds({ buffer = bufnr, group = augroup_setup })
|
||||
end,
|
||||
|
Reference in New Issue
Block a user