Skip to content

Commit 22d5ee4

Browse files
authored
fix: add logging for command execution errors in VSCodeCmdTool (#395)
1 parent 7664f4a commit 22d5ee4

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/extension/tools/node/vscodeCmdTool.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import * as l10n from '@vscode/l10n';
77
import type * as vscode from 'vscode';
88
import { IRunCommandExecutionService } from '../../../platform/commands/common/runCommandExecutionService';
9+
import { ILogService } from '../../../platform/log/common/logService';
910
import { IWorkbenchService } from '../../../platform/workbench/common/workbenchService';
1011
import { CancellationToken } from '../../../util/vs/base/common/cancellation';
1112
import { LanguageModelTextPart, LanguageModelToolResult, MarkdownString } from '../../../vscodeTypes';
@@ -25,11 +26,12 @@ class VSCodeCmdTool implements vscode.LanguageModelTool<IVSCodeCmdToolToolInput>
2526
constructor(
2627
@IRunCommandExecutionService private readonly _commandService: IRunCommandExecutionService,
2728
@IWorkbenchService private readonly _workbenchService: IWorkbenchService,
29+
@ILogService private readonly _logService: ILogService
2830
) { }
2931

3032
async invoke(options: vscode.LanguageModelToolInvocationOptions<IVSCodeCmdToolToolInput>, token: CancellationToken): Promise<vscode.LanguageModelToolResult> {
3133
const command = options.input.commandId;
32-
const args = options.input.args;
34+
const args = options.input.args ?? [];
3335

3436
const allcommands = (await this._workbenchService.getAllCommands(/* filterByPreCondition */true));
3537
const commandItem = allcommands.find(commandItem => commandItem.command === command);
@@ -41,6 +43,7 @@ class VSCodeCmdTool implements vscode.LanguageModelTool<IVSCodeCmdToolToolInput>
4143
await this._commandService.executeCommand(command, ...args);
4244
return new LanguageModelToolResult([new LanguageModelTextPart(`Finished running ${options.input.name} command`)]);
4345
} catch (error) {
46+
this._logService.error(`[VSCodeCmdTool] ${error}`);
4447
return new LanguageModelToolResult([new LanguageModelTextPart(`Failed to run ${options.input.name} command.`)]);
4548
}
4649
}

0 commit comments

Comments
 (0)