@@ -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 } from './types' ;
@@ -60,8 +60,7 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
60
60
61
61
public async activate ( resource : Resource ) : Promise < void > {
62
62
if ( ! inTerminalEnvVarExperiment ( this . experimentService ) ) {
63
- const workspaceFolder = this . getWorkspaceFolder ( resource ) ;
64
- this . context . getEnvironmentVariableCollection ( { workspaceFolder } ) . clear ( ) ;
63
+ this . context . environmentVariableCollection . clear ( ) ;
65
64
await this . handleMicroVenv ( resource ) ;
66
65
if ( ! this . registeredOnce ) {
67
66
this . interpreterService . onDidChangeInterpreter (
@@ -168,22 +167,26 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
168
167
}
169
168
170
169
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
+ }
184
185
}
186
+ this . context . getEnvironmentVariableCollection ( { workspaceFolder } ) . clear ( ) ;
187
+ } catch ( ex ) {
188
+ traceWarn ( `Microvenv failed as it is using proposed API which is constantly changing` , ex ) ;
185
189
}
186
- this . context . getEnvironmentVariableCollection ( { workspaceFolder } ) . clear ( ) ;
187
190
}
188
191
189
192
private getWorkspaceFolder ( resource : Resource ) : WorkspaceFolder | undefined {
0 commit comments