aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/_folding_range.lua
diff options
context:
space:
mode:
authorYi Ming <ofseed@foxmail.com>2025-02-12 22:22:59 +0800
committerGitHub <noreply@github.com>2025-02-12 06:22:59 -0800
commitbe8d87014c0c120ece50aabff307c1f5d9167ec0 (patch)
tree2a3bf35919203553c0e3449b3a4a18261d80e954 /runtime/lua/vim/lsp/_folding_range.lua
parent2c629ad13f19ac262c0ae85628ceec6d4e0243fb (diff)
downloadrneovim-be8d87014c0c120ece50aabff307c1f5d9167ec0.tar.gz
rneovim-be8d87014c0c120ece50aabff307c1f5d9167ec0.tar.bz2
rneovim-be8d87014c0c120ece50aabff307c1f5d9167ec0.zip
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.
Diffstat (limited to 'runtime/lua/vim/lsp/_folding_range.lua')
-rw-r--r--runtime/lua/vim/lsp/_folding_range.lua5
1 files changed, 5 insertions, 0 deletions
diff --git a/runtime/lua/vim/lsp/_folding_range.lua b/runtime/lua/vim/lsp/_folding_range.lua
index 66eb81db6e..65143e6e50 100644
--- a/runtime/lua/vim/lsp/_folding_range.lua
+++ b/runtime/lua/vim/lsp/_folding_range.lua
@@ -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,