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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
"%python-envs.terminal.autoActivationType.shellStartup%",
"%python-envs.terminal.autoActivationType.off%"
],
"scope": "machine"
"scope": "window"
},
"python.terminal.useEnvFile": {
"type": "boolean",
Expand Down
18 changes: 13 additions & 5 deletions src/features/terminal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -402,9 +404,15 @@ export function getAutoActivationType(): AutoActivationType {
const pyEnvsActivationType = pyEnvsConfig.inspect<AutoActivationType>('terminal.autoActivationType');

if (pyEnvsActivationType) {
// Priority order: globalRemoteValue > globalLocalValue > globalValue
// Priority order: workspaceFolderValue > workspaceValue > globalRemoteValue > globalLocalValue > globalValue
const activationType = pyEnvsActivationType as Record<string, unknown>;

if (pyEnvsActivationType.workspaceFolderValue !== undefined) {
return pyEnvsActivationType.workspaceFolderValue;
}
if (pyEnvsActivationType.workspaceValue !== undefined) {
return pyEnvsActivationType.workspaceValue;
Comment on lines +413 to +414
}
if ('globalRemoteValue' in pyEnvsActivationType && activationType.globalRemoteValue !== undefined) {
return activationType.globalRemoteValue as AutoActivationType;
}
Expand Down
41 changes: 40 additions & 1 deletion src/test/features/terminal/utils.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down