fix: support cancelling acp providers (#2847)

This commit is contained in:
Peter Cardenas
2025-12-16 03:07:10 -08:00
committed by GitHub
parent 92f972a413
commit 80f7079556
2 changed files with 26 additions and 1 deletions

View File

@@ -1541,7 +1541,28 @@ function M._stream_acp(opts)
end
end
end
local cancelled = false
local stop_cmd_id = api.nvim_create_autocmd("User", {
group = group,
pattern = M.CANCEL_PATTERN,
once = true,
callback = function()
cancelled = true
local cancelled_text = "\n*[Request cancelled by user.]*\n"
if opts.on_chunk then opts.on_chunk(cancelled_text) end
if opts.on_messages_add then
local message = History.Message:new("assistant", cancelled_text, {
just_for_display = true,
})
opts.on_messages_add({ message })
end
acp_client:cancel_session(session_id)
opts.on_stop({ reason = "cancelled" })
end,
})
acp_client:send_prompt(session_id, prompt, function(_, err_)
if cancelled then return end
api.nvim_del_autocmd(stop_cmd_id)
if err_ then
-- ACP-specific session recovery: Check for session not found error
-- Check for session recovery conditions

View File

@@ -2813,7 +2813,11 @@ function Sidebar:handle_submit(request)
return
end
on_state_change("succeeded")
if stop_opts.reason == "cancelled" then
on_state_change("cancelled")
else
on_state_change("succeeded")
end
self:update_content("", {
callback = function() api.nvim_exec_autocmds("User", { pattern = VIEW_BUFFER_UPDATED_PATTERN }) end,