Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/client/envExt/api.internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,17 @@ export function useEnvExtension(): boolean {
}
const config = getConfiguration('python');
const inExpSetting = config?.get<boolean>('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<DidChangeEnvironmentEventArgs> = new EventEmitter<
DidChangeEnvironmentEventArgs
>();
Expand Down
34 changes: 34 additions & 0 deletions src/test/common/terminals/activator/index.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Loading