Skip to content

Commit d7af377

Browse files
Fix: Open file browser at workspace root when selecting interpreter path (#25520)
## Problem When users click "Enter interpreter path..." and then select "Find..." to browse for a Python interpreter, the file browser dialog opens at the user's home directory instead of the current workspace root. This creates a frustrating experience when trying to navigate to virtual environments (like `.venv`) or other interpreters located within the project directory. ![File browser opening at wrong location](https://github.com/user-attachments/assets/8cbb89e6-8f1b-4ff2-8f15-d44ef6a7d01f) ## Solution Added the `defaultUri` parameter to the `showOpenDialog` call in the `_enterOrBrowseInterpreterPath` method. This parameter is set to `state.workspace`, which contains the current workspace folder URI when a workspace is open. ```typescript const uris = await this.applicationShell.showOpenDialog({ filters: this.platformService.isWindows ? filtersObject : undefined, openLabel: InterpreterQuickPickList.browsePath.openButtonLabel, canSelectMany: false, title: InterpreterQuickPickList.browsePath.title, defaultUri: state.workspace, // ← Added this line }); ``` ## Impact - **With workspace open:** File browser now opens at the workspace root directory, making it easy to find `.venv` folders and project-specific interpreters - **Without workspace open:** Behavior unchanged - file browser opens at the default location (typically user's home directory) ## Testing - Updated all existing unit tests to include the new `defaultUri` parameter in expected values - Added new test case: "If `Browse...` option is selected with workspace, file browser opens at workspace root" - All 35 tests in the "Set Interpreter Command" suite pass ✅ Fixes issue where users expected the file browser to open in their current project directory when browsing for interpreters, improving the user experience when setting up virtual environments in VS Code. Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: eleanorjboyd <[email protected]>
1 parent d970068 commit d7af377

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/client/interpreter/configuration/interpreterSelector/commands/setInterpreter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ export class SetInterpreterCommand extends BaseInterpreterSelectorCommand implem
554554
openLabel: InterpreterQuickPickList.browsePath.openButtonLabel,
555555
canSelectMany: false,
556556
title: InterpreterQuickPickList.browsePath.title,
557+
defaultUri: state.workspace,
557558
});
558559
if (uris && uris.length > 0) {
559560
state.path = uris[0].fsPath;

src/test/configuration/interpreterSelector/commands/setInterpreter.unit.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,7 @@ suite('Set Interpreter Command', () => {
10521052
openLabel: InterpreterQuickPickList.browsePath.openButtonLabel,
10531053
canSelectMany: false,
10541054
title: InterpreterQuickPickList.browsePath.title,
1055+
defaultUri: undefined,
10551056
};
10561057
const multiStepInput = TypeMoq.Mock.ofType<IMultiStepInput<InterpreterStateArgs>>();
10571058
multiStepInput.setup((i) => i.showQuickPick(TypeMoq.It.isAny())).returns(() => Promise.resolve(items[0]));
@@ -1073,6 +1074,27 @@ suite('Set Interpreter Command', () => {
10731074
openLabel: InterpreterQuickPickList.browsePath.openButtonLabel,
10741075
canSelectMany: false,
10751076
title: InterpreterQuickPickList.browsePath.title,
1077+
defaultUri: undefined,
1078+
};
1079+
multiStepInput.setup((i) => i.showQuickPick(TypeMoq.It.isAny())).returns(() => Promise.resolve(items[0]));
1080+
appShell.setup((a) => a.showOpenDialog(expectedParams)).verifiable(TypeMoq.Times.once());
1081+
platformService.setup((p) => p.isWindows).returns(() => false);
1082+
1083+
await setInterpreterCommand._enterOrBrowseInterpreterPath(multiStepInput.object, state).ignoreErrors();
1084+
1085+
appShell.verifyAll();
1086+
});
1087+
1088+
test('If `Browse...` option is selected with workspace, file browser opens at workspace root', async () => {
1089+
const workspaceUri = Uri.parse('file:///workspace/root');
1090+
const state: InterpreterStateArgs = { path: undefined, workspace: workspaceUri };
1091+
const multiStepInput = TypeMoq.Mock.ofType<IMultiStepInput<InterpreterStateArgs>>();
1092+
const expectedParams = {
1093+
filters: undefined,
1094+
openLabel: InterpreterQuickPickList.browsePath.openButtonLabel,
1095+
canSelectMany: false,
1096+
title: InterpreterQuickPickList.browsePath.title,
1097+
defaultUri: workspaceUri,
10761098
};
10771099
multiStepInput.setup((i) => i.showQuickPick(TypeMoq.It.isAny())).returns(() => Promise.resolve(items[0]));
10781100
appShell.setup((a) => a.showOpenDialog(expectedParams)).verifiable(TypeMoq.Times.once());
@@ -1126,6 +1148,7 @@ suite('Set Interpreter Command', () => {
11261148
openLabel: InterpreterQuickPickList.browsePath.openButtonLabel,
11271149
canSelectMany: false,
11281150
title: InterpreterQuickPickList.browsePath.title,
1151+
defaultUri: undefined,
11291152
};
11301153
multiStepInput
11311154
.setup((i) => i.showQuickPick(TypeMoq.It.isAny()))

0 commit comments

Comments
 (0)