diff --git a/src/client/envExt/api.internal.ts b/src/client/envExt/api.internal.ts index 5edfb712072e..8ae1d24cdaf7 100644 --- a/src/client/envExt/api.internal.ts +++ b/src/client/envExt/api.internal.ts @@ -61,11 +61,17 @@ export function useEnvExtension(): boolean { } const config = getConfiguration('python'); const inExpSetting = config?.get('useEnvironmentsExtension', false) ?? false; - // If extension is installed and in experiment, then use it. - _useExt = !!getExtension(ENVS_EXTENSION_ID) && inExpSetting; + // Use the extension only when it will also accept activation. + _useExt = inExpSetting && shouldEnvExtHandleActivation(); return _useExt; } +export const EnvExtApiInternalTests = { + resetState: (): void => { + _useExt = undefined; + }, +}; + const onDidChangeEnvironmentEnvExtEmitter: EventEmitter = new EventEmitter< DidChangeEnvironmentEventArgs >(); diff --git a/src/test/common/terminals/activator/index.unit.test.ts b/src/test/common/terminals/activator/index.unit.test.ts index 34d1cf8f1bcd..d31c9d897c8a 100644 --- a/src/test/common/terminals/activator/index.unit.test.ts +++ b/src/test/common/terminals/activator/index.unit.test.ts @@ -207,3 +207,37 @@ suite('shouldEnvExtHandleActivation', () => { assert.strictEqual(extapi.shouldEnvExtHandleActivation(), false); }); }); + +suite('useEnvExtension', () => { + let getConfigurationStub: sinon.SinonStub; + + setup(() => { + extapi.EnvExtApiInternalTests.resetState(); + const getExtensionStub: sinon.SinonStub = sinon.stub(extensionsApi, 'getExtension'); + getExtensionStub.returns({ id: extapi.ENVS_EXTENSION_ID }); + sinon.stub(workspaceApis, 'getWorkspaceFolders').returns(undefined); + getConfigurationStub = sinon.stub(workspaceApis, 'getConfiguration'); + getConfigurationStub.returns({ + get: () => true, + inspect: () => ({ globalValue: false, workspaceValue: true }), + }); + }); + + teardown(() => { + extapi.EnvExtApiInternalTests.resetState(); + sinon.restore(); + }); + + test('Returns false when the effective workspace value is true but the global value is false', () => { + assert.strictEqual(extapi.useEnvExtension(), false); + }); + + test('Returns true when the effective value is true and no scope explicitly disables the extension', () => { + getConfigurationStub.returns({ + get: () => true, + inspect: () => ({ globalValue: undefined, workspaceValue: true }), + }); + + assert.strictEqual(extapi.useEnvExtension(), true); + }); +});