Skip to content

Commit f938935

Browse files
eleanorjboydCopilot
andcommitted
Fix environment extension scope activation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 02fe7d0 commit f938935

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

src/client/envExt/api.internal.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,17 @@ export function useEnvExtension(): boolean {
6161
}
6262
const config = getConfiguration('python');
6363
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;
64+
// Use the extension only when it will also accept activation.
65+
_useExt = inExpSetting && shouldEnvExtHandleActivation();
6666
return _useExt;
6767
}
6868

69+
export const EnvExtApiInternalTests = {
70+
resetState: (): void => {
71+
_useExt = undefined;
72+
},
73+
};
74+
6975
const onDidChangeEnvironmentEnvExtEmitter: EventEmitter<DidChangeEnvironmentEventArgs> = new EventEmitter<
7076
DidChangeEnvironmentEventArgs
7177
>();

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,37 @@ suite('shouldEnvExtHandleActivation', () => {
207207
assert.strictEqual(extapi.shouldEnvExtHandleActivation(), false);
208208
});
209209
});
210+
211+
suite('useEnvExtension', () => {
212+
let getConfigurationStub: sinon.SinonStub;
213+
214+
setup(() => {
215+
extapi.EnvExtApiInternalTests.resetState();
216+
const getExtensionStub: sinon.SinonStub = sinon.stub(extensionsApi, 'getExtension');
217+
getExtensionStub.returns({ id: extapi.ENVS_EXTENSION_ID });
218+
sinon.stub(workspaceApis, 'getWorkspaceFolders').returns(undefined);
219+
getConfigurationStub = sinon.stub(workspaceApis, 'getConfiguration');
220+
getConfigurationStub.returns({
221+
get: () => true,
222+
inspect: () => ({ globalValue: false, workspaceValue: true }),
223+
});
224+
});
225+
226+
teardown(() => {
227+
extapi.EnvExtApiInternalTests.resetState();
228+
sinon.restore();
229+
});
230+
231+
test('Returns false when the effective workspace value is true but the global value is false', () => {
232+
assert.strictEqual(extapi.useEnvExtension(), false);
233+
});
234+
235+
test('Returns true when the effective value is true and no scope explicitly disables the extension', () => {
236+
getConfigurationStub.returns({
237+
get: () => true,
238+
inspect: () => ({ globalValue: undefined, workspaceValue: true }),
239+
});
240+
241+
assert.strictEqual(extapi.useEnvExtension(), true);
242+
});
243+
});

0 commit comments

Comments
 (0)