@@ -27,7 +27,7 @@ import { resolveFilePath } from './utils';
2727import { ITerminalHelper } from '../common/terminal/types' ;
2828import { IRecommendedEnvironmentService } from '../interpreter/configuration/types' ;
2929import { CreateVirtualEnvTool } from './createVirtualEnvTool' ;
30- import { SelectPythonEnvTool } from './selectEnvTool' ;
30+ import { ISelectPythonEnvToolArguments , SelectPythonEnvTool } from './selectEnvTool' ;
3131
3232export class ConfigurePythonEnvTool implements LanguageModelTool < IResourceReference > {
3333 private readonly terminalExecutionService : TerminalCodeExecutionProvider ;
@@ -37,7 +37,7 @@ export class ConfigurePythonEnvTool implements LanguageModelTool<IResourceRefere
3737 constructor (
3838 private readonly api : PythonExtension [ 'environments' ] ,
3939 private readonly serviceContainer : IServiceContainer ,
40- private readonly createVirtualEnvTool : CreateVirtualEnvTool ,
40+ private readonly createEnvTool : CreateVirtualEnvTool ,
4141 ) {
4242 this . terminalExecutionService = this . serviceContainer . get < TerminalCodeExecutionProvider > (
4343 ICodeExecutionService ,
@@ -75,22 +75,26 @@ export class ConfigurePythonEnvTool implements LanguageModelTool<IResourceRefere
7575 ) ;
7676 }
7777
78- let reason : 'cancelled' | undefined ;
79- if (
80- await this . createVirtualEnvTool . canCreateNewVirtualEnv ( resolveFilePath ( options . input . resourcePath ) , token )
81- ) {
82- reason = 'cancelled' ;
78+ if ( await this . createEnvTool . shouldCreateNewVirtualEnv ( resource , token ) ) {
8379 try {
8480 return await lm . invokeTool ( CreateVirtualEnvTool . toolName , options , token ) ;
8581 } catch ( ex ) {
86- // If the user cancelled the tool, then we should not invoke the select env tool.
87- if ( ! isCancellationError ( ex ) ) {
88- throw ex ;
82+ if ( isCancellationError ( ex ) ) {
83+ const input : ISelectPythonEnvToolArguments = {
84+ ...options . input ,
85+ reason : 'cancelled' ,
86+ } ;
87+ // If the user cancelled the tool, then we should invoke the select env tool.
88+ return lm . invokeTool ( SelectPythonEnvTool . toolName , { ...options , input } , token ) ;
8989 }
90+ throw ex ;
9091 }
92+ } else {
93+ const input : ISelectPythonEnvToolArguments = {
94+ ...options . input ,
95+ } ;
96+ return lm . invokeTool ( SelectPythonEnvTool . toolName , { ...options , input } , token ) ;
9197 }
92-
93- return lm . invokeTool ( SelectPythonEnvTool . toolName , { ...options , input : { ...options . input , reason } } , token ) ;
9498 }
9599
96100 async prepareInvocation ?(
0 commit comments