Skip to content

Commit a93cb3e

Browse files
committed
Fix environment extension activation scope mismatch
Assisted-by: OpenAI Codex
1 parent 757def8 commit a93cb3e

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

src/client/envExt/api.internal.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,19 @@ export function shouldEnvExtHandleActivation(): boolean {
5555
}
5656

5757
let _useExt: boolean | undefined;
58+
export function shouldUseEnvExtension(): boolean {
59+
const config = getConfiguration('python');
60+
const inExpSetting = config?.get<boolean>('useEnvironmentsExtension', false) ?? false;
61+
return inExpSetting && shouldEnvExtHandleActivation();
62+
}
63+
5864
export function useEnvExtension(): boolean {
5965
if (_useExt !== undefined) {
6066
return _useExt;
6167
}
62-
const config = getConfiguration('python');
63-
const inExpSetting = config?.get<boolean>('useEnvironmentsExtension', false) ?? false;
64-
// If extension is installed and in experiment, then use it.
65-
_useExt = !!getExtension(ENVS_EXTENSION_ID) && inExpSetting;
68+
// Use the extension only when it is enabled and its own activation logic
69+
// will expose the API.
70+
_useExt = shouldUseEnvExtension();
6671
return _useExt;
6772
}
6873

src/test/common/terminals/activator/index.unit.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,15 @@ suite('shouldEnvExtHandleActivation', () => {
174174
assert.strictEqual(extapi.shouldEnvExtHandleActivation(), false);
175175
});
176176

177+
test('Does not use envs extension when workspace enables it but user settings disable activation', () => {
178+
getExtensionStub.returns({ id: extapi.ENVS_EXTENSION_ID });
179+
getConfigurationStub.returns({
180+
get: () => true,
181+
inspect: () => ({ globalValue: false, workspaceValue: true }),
182+
});
183+
assert.strictEqual(extapi.shouldUseEnvExtension(), false);
184+
});
185+
177186
test('Returns false when envs extension is installed but workspaceValue is false', () => {
178187
getExtensionStub.returns({ id: extapi.ENVS_EXTENSION_ID });
179188
getConfigurationStub.returns({

0 commit comments

Comments
 (0)