Skip to content

Commit c815697

Browse files
authored
Merge branch 'main' into copilot/fix-478
2 parents 5fb900c + f0d3ec5 commit c815697

4 files changed

Lines changed: 55 additions & 5 deletions

File tree

src/common/pickers/managers.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { commands, QuickInputButtons, QuickPickItem, QuickPickItemKind } from 'vscode';
1+
import { commands, QuickInputButtons, QuickPickItem, QuickPickItemKind, workspace, WorkspaceFolder } from 'vscode';
22
import { PythonProjectCreator } from '../../api';
33
import { InternalEnvironmentManager, InternalPackageManager } from '../../internal.api';
44
import { Common, Pickers } from '../localize';
@@ -125,6 +125,31 @@ export async function pickPackageManager(
125125
return (item as QuickPickItem & { id: string })?.id;
126126
}
127127

128+
export async function pickWorkspaceFolder(showBackButton = true): Promise<WorkspaceFolder | undefined> {
129+
const folders = workspace.workspaceFolders;
130+
if (!folders || folders.length === 0) {
131+
return undefined;
132+
}
133+
if (folders.length === 1) {
134+
return folders[0];
135+
}
136+
const items = folders.map((f) => ({
137+
label: f.name,
138+
description: f.uri.fsPath,
139+
folder: f,
140+
}));
141+
142+
const selected = await showQuickPickWithButtons(items, {
143+
placeHolder: 'Select a workspace folder',
144+
ignoreFocusOut: true,
145+
showBackButton,
146+
});
147+
if (!selected) {
148+
return undefined;
149+
}
150+
const selectedItem = Array.isArray(selected) ? selected[0] : selected;
151+
return selectedItem?.folder;
152+
}
128153
export async function pickCreator(creators: PythonProjectCreator[]): Promise<PythonProjectCreator | undefined> {
129154
if (creators.length === 0) {
130155
return;

src/features/envCommands.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { commands, QuickInputButtons, TaskExecution, TaskRevealKind, Terminal, Uri } from 'vscode';
1+
import { commands, QuickInputButtons, TaskExecution, TaskRevealKind, Terminal, Uri, workspace } from 'vscode';
22
import {
33
CreateEnvironmentOptions,
44
PythonEnvironment,
@@ -20,7 +20,12 @@ import { removePythonProjectSetting, setEnvironmentManager, setPackageManager }
2020
import { clipboardWriteText } from '../common/env.apis';
2121
import {} from '../common/errors/utils';
2222
import { pickEnvironment } from '../common/pickers/environments';
23-
import { pickCreator, pickEnvironmentManager, pickPackageManager } from '../common/pickers/managers';
23+
import {
24+
pickCreator,
25+
pickEnvironmentManager,
26+
pickPackageManager,
27+
pickWorkspaceFolder,
28+
} from '../common/pickers/managers';
2429
import { pickProject, pickProjectMany } from '../common/pickers/projects';
2530
import { activeTextEditor, showErrorMessage, showInformationMessage, showTextDocument } from '../common/window.apis';
2631
import { quoteArgs } from './execution/execUtils';
@@ -451,6 +456,20 @@ export async function addPythonProjectCommand(
451456
return;
452457
}
453458

459+
// if multiroot, prompt the user to select which workspace to create the project in
460+
const workspaceFolders = workspace.workspaceFolders;
461+
if (!resource && workspaceFolders && workspaceFolders.length > 1) {
462+
try {
463+
const workspace = await pickWorkspaceFolder(true);
464+
resource = workspace?.uri;
465+
} catch (ex) {
466+
if (ex === QuickInputButtons.Back) {
467+
return addPythonProjectCommand(resource, wm, em, pc);
468+
}
469+
throw ex;
470+
}
471+
}
472+
454473
try {
455474
const result = await creator.create(options);
456475
if (result instanceof Uri) {

src/managers/builtin/venvManager.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ export class VenvManager implements EnvironmentManager {
171171
try {
172172
this.skipWatcherRefresh = true;
173173

174-
await removeVenv(environment, this.log);
174+
const isRemoved = await removeVenv(environment, this.log);
175+
if (!isRemoved) {
176+
return;
177+
}
175178
this.updateCollection(environment);
176179
this._onDidChangeEnvironments.fire([{ environment, kind: EnvironmentChangeKind.remove }]);
177180

src/managers/builtin/venvUtils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from '../../api';
1212
import { ENVS_EXTENSION_ID } from '../../common/constants';
1313
import { Common, VenvManagerStrings } from '../../common/localize';
14+
import { traceInfo } from '../../common/logging';
1415
import { getWorkspacePersistentState } from '../../common/persistentState';
1516
import { pickEnvironmentFrom } from '../../common/pickers/environments';
1617
import { EventNames } from '../../common/telemetry/constants';
@@ -561,7 +562,7 @@ export async function removeVenv(environment: PythonEnvironment, log: LogOutputC
561562
{ title: Common.no, isCloseAffordance: true },
562563
);
563564
if (confirm?.title === Common.yes) {
564-
await withProgress(
565+
const result = await withProgress(
565566
{
566567
location: ProgressLocation.Notification,
567568
title: VenvManagerStrings.venvRemoving,
@@ -577,8 +578,10 @@ export async function removeVenv(environment: PythonEnvironment, log: LogOutputC
577578
}
578579
},
579580
);
581+
return result;
580582
}
581583

584+
traceInfo(`User cancelled removal of virtual environment: ${envPath}`);
582585
return false;
583586
}
584587

0 commit comments

Comments
 (0)