@@ -20,7 +20,7 @@ import {
2020} from '../../common/types' ;
2121import { Deferred , createDeferred } from '../../common/utils/async' ;
2222import { Interpreters } from '../../common/utils/localize' ;
23- import { traceDecoratorVerbose , traceVerbose } from '../../logging' ;
23+ import { traceDecoratorVerbose , traceVerbose , traceWarn } from '../../logging' ;
2424import { IInterpreterService } from '../contracts' ;
2525import { defaultShells } from './service' ;
2626import { IEnvironmentActivationService } from './types' ;
@@ -60,8 +60,7 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
6060
6161 public async activate ( resource : Resource ) : Promise < void > {
6262 if ( ! inTerminalEnvVarExperiment ( this . experimentService ) ) {
63- const workspaceFolder = this . getWorkspaceFolder ( resource ) ;
64- this . context . getEnvironmentVariableCollection ( { workspaceFolder } ) . clear ( ) ;
63+ this . context . environmentVariableCollection . clear ( ) ;
6564 await this . handleMicroVenv ( resource ) ;
6665 if ( ! this . registeredOnce ) {
6766 this . interpreterService . onDidChangeInterpreter (
@@ -168,22 +167,26 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
168167 }
169168
170169 private async handleMicroVenv ( resource : Resource ) {
171- const workspaceFolder = this . getWorkspaceFolder ( resource ) ;
172- const interpreter = await this . interpreterService . getActiveInterpreter ( resource ) ;
173- if ( interpreter ?. envType === EnvironmentType . Venv ) {
174- const activatePath = path . join ( path . dirname ( interpreter . path ) , 'activate' ) ;
175- if ( ! ( await pathExists ( activatePath ) ) ) {
176- const envVarCollection = this . context . getEnvironmentVariableCollection ( { workspaceFolder } ) ;
177- const pathVarName = getSearchPathEnvVarNames ( ) [ 0 ] ;
178- envVarCollection . replace (
179- 'PATH' ,
180- `${ path . dirname ( interpreter . path ) } ${ path . delimiter } ${ process . env [ pathVarName ] } ` ,
181- { applyAtShellIntegration : true } ,
182- ) ;
183- return ;
170+ try {
171+ const workspaceFolder = this . getWorkspaceFolder ( resource ) ;
172+ const interpreter = await this . interpreterService . getActiveInterpreter ( resource ) ;
173+ if ( interpreter ?. envType === EnvironmentType . Venv ) {
174+ const activatePath = path . join ( path . dirname ( interpreter . path ) , 'activate' ) ;
175+ if ( ! ( await pathExists ( activatePath ) ) ) {
176+ const envVarCollection = this . context . getEnvironmentVariableCollection ( { workspaceFolder } ) ;
177+ const pathVarName = getSearchPathEnvVarNames ( ) [ 0 ] ;
178+ envVarCollection . replace (
179+ 'PATH' ,
180+ `${ path . dirname ( interpreter . path ) } ${ path . delimiter } ${ process . env [ pathVarName ] } ` ,
181+ { applyAtShellIntegration : true } ,
182+ ) ;
183+ return ;
184+ }
184185 }
186+ this . context . getEnvironmentVariableCollection ( { workspaceFolder } ) . clear ( ) ;
187+ } catch ( ex ) {
188+ traceWarn ( `Microvenv failed as it is using proposed API which is constantly changing` , ex ) ;
185189 }
186- this . context . getEnvironmentVariableCollection ( { workspaceFolder } ) . clear ( ) ;
187190 }
188191
189192 private getWorkspaceFolder ( resource : Resource ) : WorkspaceFolder | undefined {
0 commit comments