@@ -20,7 +20,7 @@ import {
20
20
} from '../../common/types' ;
21
21
import { Deferred , createDeferred } from '../../common/utils/async' ;
22
22
import { Interpreters } from '../../common/utils/localize' ;
23
- import { traceDecoratorVerbose , traceVerbose } from '../../logging' ;
23
+ import { traceDecoratorVerbose , traceVerbose , traceWarn } from '../../logging' ;
24
24
import { IInterpreterService } from '../contracts' ;
25
25
import { defaultShells } from './service' ;
26
26
import { IEnvironmentActivationService , ITerminalEnvVarCollectionService } from './types' ;
@@ -62,8 +62,7 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
62
62
63
63
public async activate ( resource : Resource ) : Promise < void > {
64
64
if ( ! inTerminalEnvVarExperiment ( this . experimentService ) ) {
65
- const workspaceFolder = this . getWorkspaceFolder ( resource ) ;
66
- this . context . getEnvironmentVariableCollection ( { workspaceFolder } ) . clear ( ) ;
65
+ this . context . environmentVariableCollection . clear ( ) ;
67
66
await this . handleMicroVenv ( resource ) ;
68
67
if ( ! this . registeredOnce ) {
69
68
this . interpreterService . onDidChangeInterpreter (
@@ -227,22 +226,26 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
227
226
}
228
227
229
228
private async handleMicroVenv ( resource : Resource ) {
230
- const workspaceFolder = this . getWorkspaceFolder ( resource ) ;
231
- const interpreter = await this . interpreterService . getActiveInterpreter ( resource ) ;
232
- if ( interpreter ?. envType === EnvironmentType . Venv ) {
233
- const activatePath = path . join ( path . dirname ( interpreter . path ) , 'activate' ) ;
234
- if ( ! ( await pathExists ( activatePath ) ) ) {
235
- const envVarCollection = this . context . getEnvironmentVariableCollection ( { workspaceFolder } ) ;
236
- const pathVarName = getSearchPathEnvVarNames ( ) [ 0 ] ;
237
- envVarCollection . replace (
238
- 'PATH' ,
239
- `${ path . dirname ( interpreter . path ) } ${ path . delimiter } ${ process . env [ pathVarName ] } ` ,
240
- { applyAtShellIntegration : true , applyAtProcessCreation : true } ,
241
- ) ;
242
- return ;
229
+ try {
230
+ const workspaceFolder = this . getWorkspaceFolder ( resource ) ;
231
+ const interpreter = await this . interpreterService . getActiveInterpreter ( resource ) ;
232
+ if ( interpreter ?. envType === EnvironmentType . Venv ) {
233
+ const activatePath = path . join ( path . dirname ( interpreter . path ) , 'activate' ) ;
234
+ if ( ! ( await pathExists ( activatePath ) ) ) {
235
+ const envVarCollection = this . context . getEnvironmentVariableCollection ( { workspaceFolder } ) ;
236
+ const pathVarName = getSearchPathEnvVarNames ( ) [ 0 ] ;
237
+ envVarCollection . replace (
238
+ 'PATH' ,
239
+ `${ path . dirname ( interpreter . path ) } ${ path . delimiter } ${ process . env [ pathVarName ] } ` ,
240
+ { applyAtShellIntegration : true , applyAtProcessCreation : true } ,
241
+ ) ;
242
+ return ;
243
+ }
244
+ this . context . getEnvironmentVariableCollection ( { workspaceFolder } ) . clear ( ) ;
243
245
}
246
+ } catch ( ex ) {
247
+ traceWarn ( `Microvenv failed as it is using proposed API which is constantly changing` , ex ) ;
244
248
}
245
- this . context . getEnvironmentVariableCollection ( { workspaceFolder } ) . clear ( ) ;
246
249
}
247
250
248
251
private getWorkspaceFolder ( resource : Resource ) : WorkspaceFolder | undefined {
0 commit comments