Skip to content

Commit 8d8f1e7

Browse files
rakotomandimbyMihamina RKTMB
andauthored
feat(functions): add configuration parameter to stop on tool failure (CopilotC-Nvim#1364)
Co-authored-by: Mihamina RKTMB <mihamina.rakotomandimby@rktmb.org>
1 parent e879659 commit 8d8f1e7

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

lua/CopilotChat/config.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
---@field auto_fold boolean?
3636
---@field insert_at_end boolean?
3737
---@field clear_chat_on_new_prompt boolean?
38+
---@field stop_on_tool_failure boolean?
3839

3940
--- CopilotChat default configuration
4041
---@class CopilotChat.config.Config : CopilotChat.config.Shared
@@ -94,6 +95,7 @@ return {
9495
auto_insert_mode = false, -- Automatically enter insert mode when opening window and on new prompt
9596
insert_at_end = false, -- Move cursor to end of buffer when inserting text
9697
clear_chat_on_new_prompt = false, -- Clears chat on every new prompt
98+
stop_on_tool_failure = false, -- Stop processing prompt if any tool fails (preserves quota)
9799

98100
-- Static config starts here (can be configured only via setup function)
99101

lua/CopilotChat/init.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,13 @@ function M.resolve_functions(prompt, config)
413413

414414
local schema = tools[name] and tools[name].schema or nil
415415
local result = ''
416-
local ok, output = pcall(tool.resolve, functions.parse_input(input, schema), state.source)
416+
local ok, output
417+
if config.stop_on_tool_failure then
418+
output = tool.resolve(functions.parse_input(input, schema), state.source)
419+
ok = true
420+
else
421+
ok, output = pcall(tool.resolve, functions.parse_input(input, schema), state.source)
422+
end
417423
if not ok then
418424
result = string.format(BLOCK_OUTPUT_FORMAT, 'error', utils.make_string(output))
419425
else

0 commit comments

Comments
 (0)