Skip to content
Merged
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
27 changes: 26 additions & 1 deletion src/common/pickers/managers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { commands, QuickInputButtons, QuickPickItem, QuickPickItemKind } from 'vscode';
import { commands, QuickInputButtons, QuickPickItem, QuickPickItemKind, workspace, WorkspaceFolder } from 'vscode';
import { PythonProjectCreator } from '../../api';
import { InternalEnvironmentManager, InternalPackageManager } from '../../internal.api';
import { Common, Pickers } from '../localize';
Expand Down Expand Up @@ -125,6 +125,31 @@ export async function pickPackageManager(
return (item as QuickPickItem & { id: string })?.id;
}

export async function pickWorkspaceFolder(showBackButton = true): Promise<WorkspaceFolder | undefined> {
const folders = workspace.workspaceFolders;
if (!folders || folders.length === 0) {
return undefined;
}
if (folders.length === 1) {
return folders[0];
}
const items = folders.map((f) => ({
label: f.name,
description: f.uri.fsPath,
folder: f,
}));

const selected = await showQuickPickWithButtons(items, {
placeHolder: 'Select a workspace folder',
ignoreFocusOut: true,
showBackButton,
});
if (!selected) {
return undefined;
}
const selectedItem = Array.isArray(selected) ? selected[0] : selected;
return selectedItem?.folder;
}
export async function pickCreator(creators: PythonProjectCreator[]): Promise<PythonProjectCreator | undefined> {
if (creators.length === 0) {
return;
Expand Down
23 changes: 21 additions & 2 deletions src/features/envCommands.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { commands, QuickInputButtons, TaskExecution, TaskRevealKind, Terminal, Uri } from 'vscode';
import { commands, QuickInputButtons, TaskExecution, TaskRevealKind, Terminal, Uri, workspace } from 'vscode';
import {
CreateEnvironmentOptions,
PythonEnvironment,
Expand All @@ -20,7 +20,12 @@ import { removePythonProjectSetting, setEnvironmentManager, setPackageManager }
import { clipboardWriteText } from '../common/env.apis';
import {} from '../common/errors/utils';
import { pickEnvironment } from '../common/pickers/environments';
import { pickCreator, pickEnvironmentManager, pickPackageManager } from '../common/pickers/managers';
import {
pickCreator,
pickEnvironmentManager,
pickPackageManager,
pickWorkspaceFolder,
} from '../common/pickers/managers';
import { pickProject, pickProjectMany } from '../common/pickers/projects';
import { activeTextEditor, showErrorMessage, showInformationMessage } from '../common/window.apis';
import { quoteArgs } from './execution/execUtils';
Expand Down Expand Up @@ -451,6 +456,20 @@ export async function addPythonProjectCommand(
return;
}

// if multiroot, prompt the user to select which workspace to create the project in
const workspaceFolders = workspace.workspaceFolders;
if (!resource && workspaceFolders && workspaceFolders.length > 1) {
try {
const workspace = await pickWorkspaceFolder(true);
resource = workspace?.uri;
} catch (ex) {
if (ex === QuickInputButtons.Back) {
return addPythonProjectCommand(resource, wm, em, pc);
}
throw ex;
}
}

try {
await creator.create(options);
} catch (ex) {
Expand Down