Skip to content

Commit d787b7b

Browse files
edvilmeCopilot
andauthored
Choose project for terminal (#1401)
Fixes #291 <img width="1224" height="286" alt="image" src="https://github.com/user-attachments/assets/05bf5783-8f0f-4479-9b0e-e838ccc85aa2" /> This pull request updates the logic for creating terminal commands related to Python environments, focusing on how Python projects are retrieved and passed to the `pickProject` function. The changes improve consistency and clarity in how project lists are handled. **Improvements to project selection logic:** * The list of Python projects is now retrieved once and reused in both the undefined context and tree item context branches, ensuring consistency and avoiding redundant API calls. [[1]](diffhunk://#diff-aed4c8c8194da21783959fe3536c5b86f48d4c0755e2ef4092501dbc5e849419L609-R611) [[2]](diffhunk://#diff-aed4c8c8194da21783959fe3536c5b86f48d4c0755e2ef4092501dbc5e849419L644-R645) * The condition for prompting the user to pick a project has been updated to check if the list of Python projects is non-empty, which prevents unnecessary prompts when there are no projects available. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent fcb5149 commit d787b7b

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/features/envCommands.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import { removePythonProjectSetting, setEnvironmentManager, setPackageManager }
3030

3131
import { executeCommand } from '../common/command.api';
3232
import { clipboardWriteText } from '../common/env.apis';
33-
import {} from '../common/errors/utils';
3433
import { Pickers } from '../common/localize';
3534
import { pickEnvironment } from '../common/pickers/environments';
3635
import {
@@ -606,8 +605,10 @@ export async function createTerminalCommand(
606605
api: PythonEnvironmentApi,
607606
tm: TerminalManager,
608607
): Promise<Terminal | undefined> {
609-
if (context === undefined) {
610-
const pw = await pickProject(api.getPythonProjects());
608+
const pythonProjects = api.getPythonProjects();
609+
// If no context is provided, or there are multiple projects, prompt the user to select a project for the terminal's cwd
610+
if (context === undefined || pythonProjects.length > 0) {
611+
const pw = await pickProject(pythonProjects);
611612
if (pw) {
612613
const env = await api.getEnvironment(pw.uri);
613614
const cwd = await findParentIfFile(pw.uri.fsPath);
@@ -641,7 +642,7 @@ export async function createTerminalCommand(
641642
}
642643
} else if (context instanceof PythonEnvTreeItem) {
643644
const view = context as PythonEnvTreeItem;
644-
const pw = await pickProject(api.getPythonProjects());
645+
const pw = await pickProject(pythonProjects);
645646
if (pw) {
646647
const cwd = await findParentIfFile(pw.uri.fsPath);
647648
const terminal = await tm.create(view.environment, { cwd });

0 commit comments

Comments
 (0)