Skip to content

Commit 780c3fe

Browse files
committed
Handle multi-root scenario
1 parent 2e85142 commit 780c3fe

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

src/client/envExt/api.internal.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
DidChangeEnvironmentEventArgs,
1414
} from './types';
1515
import { executeCommand } from '../common/vscodeApis/commandApis';
16-
import { getConfiguration } from '../common/vscodeApis/workspaceApis';
16+
import { getConfiguration, getWorkspaceFolders } from '../common/vscodeApis/workspaceApis';
1717
import { traceError, traceLog } from '../logging';
1818
import { Interpreters } from '../common/utils/localize';
1919

@@ -26,7 +26,8 @@ export function isEnvExtensionInstalled(): boolean {
2626
/**
2727
* Returns true if the Python Environments extension is installed and not explicitly
2828
* disabled by the user. Mirrors the envs extension's own activation logic: it
29-
* deactivates only when `python.useEnvironmentsExtension` is explicitly set to false.
29+
* deactivates only when `python.useEnvironmentsExtension` is explicitly set to false
30+
* at the global, workspace, or workspace-folder level.
3031
*/
3132
export function shouldEnvExtHandleActivation(): boolean {
3233
if (!isEnvExtensionInstalled()) {
@@ -37,6 +38,19 @@ export function shouldEnvExtHandleActivation(): boolean {
3738
if (inspection?.globalValue === false || inspection?.workspaceValue === false) {
3839
return false;
3940
}
41+
// The envs extension also checks folder-scoped settings in multi-root workspaces.
42+
// Any single folder with the setting set to false causes the envs extension to
43+
// deactivate entirely (window-wide), so we must mirror that here.
44+
const workspaceFolders = getWorkspaceFolders();
45+
if (workspaceFolders) {
46+
for (const folder of workspaceFolders) {
47+
const folderConfig = getConfiguration('python', folder.uri);
48+
const folderInspection = folderConfig.inspect<boolean>('useEnvironmentsExtension');
49+
if (folderInspection?.workspaceFolderValue === false) {
50+
return false;
51+
}
52+
}
53+
}
4054
return true;
4155
}
4256

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { assert } from 'chai';
77
import * as sinon from 'sinon';
88
import * as TypeMoq from 'typemoq';
9-
import { Terminal } from 'vscode';
9+
import { Terminal, Uri } from 'vscode';
1010
import { TerminalActivator } from '../../../../client/common/terminal/activator';
1111
import {
1212
ITerminalActivationHandler,
@@ -140,10 +140,13 @@ suite('Terminal Activator', () => {
140140
suite('shouldEnvExtHandleActivation', () => {
141141
let getExtensionStub: sinon.SinonStub;
142142
let getConfigurationStub: sinon.SinonStub;
143+
let getWorkspaceFoldersStub: sinon.SinonStub;
143144

144145
setup(() => {
145146
getExtensionStub = sinon.stub(extensionsApi, 'getExtension');
146147
getConfigurationStub = sinon.stub(workspaceApis, 'getConfiguration');
148+
getWorkspaceFoldersStub = sinon.stub(workspaceApis, 'getWorkspaceFolders');
149+
getWorkspaceFoldersStub.returns(undefined);
147150
});
148151

149152
teardown(() => {
@@ -186,4 +189,21 @@ suite('shouldEnvExtHandleActivation', () => {
186189
});
187190
assert.strictEqual(extapi.shouldEnvExtHandleActivation(), true);
188191
});
192+
193+
test('Returns false when a workspace folder has workspaceFolderValue set to false', () => {
194+
getExtensionStub.returns({ id: extapi.ENVS_EXTENSION_ID });
195+
const folderUri = Uri.parse('file:///workspace/folder1');
196+
getWorkspaceFoldersStub.returns([{ uri: folderUri, name: 'folder1', index: 0 }]);
197+
getConfigurationStub.callsFake((_section: string, scope?: Uri) => {
198+
if (scope) {
199+
return {
200+
inspect: () => ({ workspaceFolderValue: false }),
201+
};
202+
}
203+
return {
204+
inspect: () => ({ globalValue: undefined, workspaceValue: undefined }),
205+
};
206+
});
207+
assert.strictEqual(extapi.shouldEnvExtHandleActivation(), false);
208+
});
189209
});

0 commit comments

Comments
 (0)