@@ -21,6 +21,7 @@ import {
21
21
getDisplayVersion ,
22
22
getEnvDetailsForResponse ,
23
23
IResourceReference ,
24
+ isCancellationError ,
24
25
raceCancellationError ,
25
26
} from './utils' ;
26
27
import { resolveFilePath } from './utils' ;
@@ -35,6 +36,7 @@ import { convertEnvInfoToPythonEnvironment } from '../pythonEnvironments/legacyI
35
36
import { sortInterpreters } from '../interpreter/helpers' ;
36
37
import { isStableVersion } from '../pythonEnvironments/info/pythonVersion' ;
37
38
import { createVirtualEnvironment } from '../pythonEnvironments/creation/createEnvApi' ;
39
+ import { traceError , traceWarn } from '../logging' ;
38
40
39
41
export class CreateVirtualEnvTool implements LanguageModelTool < IResourceReference > {
40
42
private readonly terminalExecutionService : TerminalCodeExecutionProvider ;
@@ -64,6 +66,7 @@ export class CreateVirtualEnvTool implements LanguageModelTool<IResourceReferenc
64
66
const resource = resolveFilePath ( options . input . resourcePath ) ;
65
67
let info = await this . getPreferredEnvForCreation ( resource ) ;
66
68
if ( ! info ) {
69
+ traceWarn ( `${ CreateVirtualEnvTool . toolName } tool not invoked, no preferred environment found.` ) ;
67
70
return ;
68
71
}
69
72
const { workspaceFolder, preferredGlobalPythonEnv } = info ;
@@ -82,13 +85,15 @@ export class CreateVirtualEnvTool implements LanguageModelTool<IResourceReferenc
82
85
token ,
83
86
) ;
84
87
if ( ! created ?. path ) {
88
+ traceWarn ( `${ CreateVirtualEnvTool . toolName } tool not invoked, no preferred environment found.` ) ;
85
89
return ;
86
90
}
87
91
// Wait a few secs to ensure the env is selected as the active environment..
88
92
// If this doesn't work, then something went wrong.
89
93
await raceTimeout ( 5_000 , interpreterChanged ) ;
90
94
const env = await this . api . resolveEnvironment ( created . path ) ;
91
95
if ( ! env ) {
96
+ traceError ( `${ CreateVirtualEnvTool . toolName } tool not invoked, no preferred environment found.` ) ;
92
97
return ;
93
98
}
94
99
return await getEnvDetailsForResponse (
@@ -99,6 +104,16 @@ export class CreateVirtualEnvTool implements LanguageModelTool<IResourceReferenc
99
104
resource ,
100
105
token ,
101
106
) ;
107
+ } catch ( ex ) {
108
+ if ( ! isCancellationError ( ex ) ) {
109
+ traceError (
110
+ `${
111
+ CreateVirtualEnvTool . toolName
112
+ } tool failed to create virtual environment for resource ${ resource ?. toString ( ) } `,
113
+ ex ,
114
+ ) ;
115
+ }
116
+ throw ex ;
102
117
} finally {
103
118
disposables . dispose ( ) ;
104
119
}
0 commit comments