diff --git a/package.json b/package.json index fe247f8b25c1..3f98b3d08b6c 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "theme": "dark" }, "engines": { - "vscode": "^1.82.0-20230809" + "vscode": "^1.81.0-20230809" }, "enableTelemetry": false, "keywords": [ diff --git a/src/client/interpreter/activation/terminalEnvVarCollectionService.ts b/src/client/interpreter/activation/terminalEnvVarCollectionService.ts index a45306132bf4..5dc716f82afa 100644 --- a/src/client/interpreter/activation/terminalEnvVarCollectionService.ts +++ b/src/client/interpreter/activation/terminalEnvVarCollectionService.ts @@ -20,7 +20,7 @@ import { } from '../../common/types'; import { Deferred, createDeferred } from '../../common/utils/async'; import { Interpreters } from '../../common/utils/localize'; -import { traceDecoratorVerbose, traceVerbose } from '../../logging'; +import { traceDecoratorVerbose, traceVerbose, traceWarn } from '../../logging'; import { IInterpreterService } from '../contracts'; import { defaultShells } from './service'; import { IEnvironmentActivationService, ITerminalEnvVarCollectionService } from './types'; @@ -62,8 +62,7 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ public async activate(resource: Resource): Promise { if (!inTerminalEnvVarExperiment(this.experimentService)) { - const workspaceFolder = this.getWorkspaceFolder(resource); - this.context.getEnvironmentVariableCollection({ workspaceFolder }).clear(); + this.context.environmentVariableCollection.clear(); await this.handleMicroVenv(resource); if (!this.registeredOnce) { this.interpreterService.onDidChangeInterpreter( @@ -227,22 +226,26 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ } private async handleMicroVenv(resource: Resource) { - const workspaceFolder = this.getWorkspaceFolder(resource); - const interpreter = await this.interpreterService.getActiveInterpreter(resource); - if (interpreter?.envType === EnvironmentType.Venv) { - const activatePath = path.join(path.dirname(interpreter.path), 'activate'); - if (!(await pathExists(activatePath))) { - const envVarCollection = this.context.getEnvironmentVariableCollection({ workspaceFolder }); - const pathVarName = getSearchPathEnvVarNames()[0]; - envVarCollection.replace( - 'PATH', - `${path.dirname(interpreter.path)}${path.delimiter}${process.env[pathVarName]}`, - { applyAtShellIntegration: true, applyAtProcessCreation: true }, - ); - return; + try { + const workspaceFolder = this.getWorkspaceFolder(resource); + const interpreter = await this.interpreterService.getActiveInterpreter(resource); + if (interpreter?.envType === EnvironmentType.Venv) { + const activatePath = path.join(path.dirname(interpreter.path), 'activate'); + if (!(await pathExists(activatePath))) { + const envVarCollection = this.context.getEnvironmentVariableCollection({ workspaceFolder }); + const pathVarName = getSearchPathEnvVarNames()[0]; + envVarCollection.replace( + 'PATH', + `${path.dirname(interpreter.path)}${path.delimiter}${process.env[pathVarName]}`, + { applyAtShellIntegration: true, applyAtProcessCreation: true }, + ); + return; + } + this.context.getEnvironmentVariableCollection({ workspaceFolder }).clear(); } + } catch (ex) { + traceWarn(`Microvenv failed as it is using proposed API which is constantly changing`, ex); } - this.context.getEnvironmentVariableCollection({ workspaceFolder }).clear(); } private getWorkspaceFolder(resource: Resource): WorkspaceFolder | undefined { diff --git a/src/test/interpreters/activation/terminalEnvVarCollectionService.unit.test.ts b/src/test/interpreters/activation/terminalEnvVarCollectionService.unit.test.ts index 86823f16a8c8..b63750e5bf73 100644 --- a/src/test/interpreters/activation/terminalEnvVarCollectionService.unit.test.ts +++ b/src/test/interpreters/activation/terminalEnvVarCollectionService.unit.test.ts @@ -124,6 +124,7 @@ suite('Terminal Environment Variable Collection Service', () => { test('When not in experiment, do not apply activated variables to the collection and clear it instead', async () => { reset(experimentService); + when(context.environmentVariableCollection).thenReturn(instance(collection)); when(experimentService.inExperimentSync(TerminalEnvVarActivation.experiment)).thenReturn(false); const applyCollectionStub = sinon.stub(terminalEnvVarCollectionService, '_applyCollection'); applyCollectionStub.resolves();