6
6
import * as l10n from '@vscode/l10n' ;
7
7
import type * as vscode from 'vscode' ;
8
8
import { IRunCommandExecutionService } from '../../../platform/commands/common/runCommandExecutionService' ;
9
+ import { ILogService } from '../../../platform/log/common/logService' ;
9
10
import { IWorkbenchService } from '../../../platform/workbench/common/workbenchService' ;
10
11
import { CancellationToken } from '../../../util/vs/base/common/cancellation' ;
11
12
import { LanguageModelTextPart , LanguageModelToolResult , MarkdownString } from '../../../vscodeTypes' ;
@@ -25,11 +26,12 @@ class VSCodeCmdTool implements vscode.LanguageModelTool<IVSCodeCmdToolToolInput>
25
26
constructor (
26
27
@IRunCommandExecutionService private readonly _commandService : IRunCommandExecutionService ,
27
28
@IWorkbenchService private readonly _workbenchService : IWorkbenchService ,
29
+ @ILogService private readonly _logService : ILogService
28
30
) { }
29
31
30
32
async invoke ( options : vscode . LanguageModelToolInvocationOptions < IVSCodeCmdToolToolInput > , token : CancellationToken ) : Promise < vscode . LanguageModelToolResult > {
31
33
const command = options . input . commandId ;
32
- const args = options . input . args ;
34
+ const args = options . input . args ?? [ ] ;
33
35
34
36
const allcommands = ( await this . _workbenchService . getAllCommands ( /* filterByPreCondition */ true ) ) ;
35
37
const commandItem = allcommands . find ( commandItem => commandItem . command === command ) ;
@@ -41,6 +43,7 @@ class VSCodeCmdTool implements vscode.LanguageModelTool<IVSCodeCmdToolToolInput>
41
43
await this . _commandService . executeCommand ( command , ...args ) ;
42
44
return new LanguageModelToolResult ( [ new LanguageModelTextPart ( `Finished running ${ options . input . name } command` ) ] ) ;
43
45
} catch ( error ) {
46
+ this . _logService . error ( `[VSCodeCmdTool] ${ error } ` ) ;
44
47
return new LanguageModelToolResult ( [ new LanguageModelTextPart ( `Failed to run ${ options . input . name } command.` ) ] ) ;
45
48
}
46
49
}
0 commit comments