diff --git a/package.json b/package.json index 0a393ed4a..7a96803b9 100644 --- a/package.json +++ b/package.json @@ -122,7 +122,7 @@ "%python-envs.terminal.autoActivationType.shellStartup%", "%python-envs.terminal.autoActivationType.off%" ], - "scope": "machine" + "scope": "window" }, "python.terminal.useEnvFile": { "type": "boolean", diff --git a/src/features/terminal/utils.ts b/src/features/terminal/utils.ts index bcac67e38..0fe72c016 100644 --- a/src/features/terminal/utils.ts +++ b/src/features/terminal/utils.ts @@ -389,10 +389,12 @@ export type AutoActivationType = 'off' | 'command' | 'shellStartup'; * * Priority order: * 1. python-envs.terminal.autoActivationType - * a. globalRemoteValue - * b. globalLocalValue - * c. globalValue - * 2. python.terminal.activateEnvironment setting (if false, returns 'off') + * a. workspaceFolderValue + * b. workspaceValue + * c. globalRemoteValue + * d. globalLocalValue + * e. globalValue + * 2. python.terminal.activateEnvironment setting (if false, returns 'off' & sets autoActivationType to 'off') * 3. Default to 'command' if no setting is found * * @returns {AutoActivationType} The determined auto-activation type @@ -402,9 +404,15 @@ export function getAutoActivationType(): AutoActivationType { const pyEnvsActivationType = pyEnvsConfig.inspect('terminal.autoActivationType'); if (pyEnvsActivationType) { - // Priority order: globalRemoteValue > globalLocalValue > globalValue + // Priority order: workspaceFolderValue > workspaceValue > globalRemoteValue > globalLocalValue > globalValue const activationType = pyEnvsActivationType as Record; + if (pyEnvsActivationType.workspaceFolderValue !== undefined) { + return pyEnvsActivationType.workspaceFolderValue; + } + if (pyEnvsActivationType.workspaceValue !== undefined) { + return pyEnvsActivationType.workspaceValue; + } if ('globalRemoteValue' in pyEnvsActivationType && activationType.globalRemoteValue !== undefined) { return activationType.globalRemoteValue as AutoActivationType; } diff --git a/src/test/features/terminal/utils.unit.test.ts b/src/test/features/terminal/utils.unit.test.ts index 8ce504492..ad9cd35f5 100644 --- a/src/test/features/terminal/utils.unit.test.ts +++ b/src/test/features/terminal/utils.unit.test.ts @@ -339,7 +339,46 @@ suite('Terminal Utils - getAutoActivationType', () => { }); suite('Priority Order Tests', () => { - test('should return globalRemoteValue when set (highest priority)', () => { + test('should return workspaceFolderValue when set (highest priority)', () => { + const mockInspectResult = { + workspaceFolderValue: ACT_TYPE_OFF, + workspaceValue: ACT_TYPE_SHELL, + globalRemoteValue: ACT_TYPE_COMMAND, + }; + pyEnvsConfig.inspect.withArgs('terminal.autoActivationType').returns(mockInspectResult); + + const result = getAutoActivationType(); + + assert.strictEqual(result, ACT_TYPE_OFF, 'Should return workspaceFolderValue when set'); + }); + + test('should return workspaceValue when workspaceFolderValue is undefined', () => { + const mockInspectResult = { + workspaceFolderValue: undefined, + workspaceValue: ACT_TYPE_SHELL, + globalRemoteValue: ACT_TYPE_COMMAND, + }; + pyEnvsConfig.inspect.withArgs('terminal.autoActivationType').returns(mockInspectResult); + + const result = getAutoActivationType(); + + assert.strictEqual(result, ACT_TYPE_SHELL, 'Should return workspaceValue when workspaceFolderValue is undefined'); + }); + + test('should ignore globalRemoteValue when workspaceValue exists', () => { + const mockInspectResult = { + workspaceValue: ACT_TYPE_OFF, + globalRemoteValue: ACT_TYPE_SHELL, + globalLocalValue: ACT_TYPE_COMMAND, + }; + pyEnvsConfig.inspect.withArgs('terminal.autoActivationType').returns(mockInspectResult); + + const result = getAutoActivationType(); + + assert.strictEqual(result, ACT_TYPE_OFF, 'Should prioritize workspaceValue over globalRemoteValue'); + }); + + test('should return globalRemoteValue when set and no workspace values exist', () => { // Mock - globalRemoteValue is set const mockInspectResult = { globalRemoteValue: ACT_TYPE_SHELL,