Skip to content

Commit dc0a2b7

Browse files
authored
feat: add button from no workspace open in new project flow (#475)
improves the problem faced here: #470 but I think ultimately we should determine a more comprehensive flow
1 parent 1add030 commit dc0a2b7

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/features/envCommands.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { QuickInputButtons, TaskExecution, TaskRevealKind, Terminal, Uri } from 'vscode';
1+
import { commands, QuickInputButtons, TaskExecution, TaskRevealKind, Terminal, Uri } from 'vscode';
22
import {
33
CreateEnvironmentOptions,
44
PythonEnvironment,
@@ -59,9 +59,7 @@ export async function refreshPackagesCommand(context: unknown, managers?: Enviro
5959
} else if (context instanceof PythonEnvTreeItem) {
6060
const view = context as PythonEnvTreeItem;
6161
const envManager =
62-
view.parent.kind === EnvTreeItemKind.environmentGroup
63-
? view.parent.parent.manager
64-
: view.parent.manager;
62+
view.parent.kind === EnvTreeItemKind.environmentGroup ? view.parent.parent.manager : view.parent.manager;
6563
const pkgManager = managers?.getPackageManager(envManager.preferredPackageManagerId);
6664
if (pkgManager) {
6765
await pkgManager.refresh(view.environment);
@@ -205,8 +203,7 @@ export async function removeEnvironmentCommand(context: unknown, managers: Envir
205203
export async function handlePackageUninstall(context: unknown, em: EnvironmentManagers) {
206204
if (context instanceof PackageTreeItem || context instanceof ProjectPackage) {
207205
const moduleName = context.pkg.name;
208-
const environment =
209-
context instanceof ProjectPackage ? context.parent.environment : context.parent.environment;
206+
const environment = context instanceof ProjectPackage ? context.parent.environment : context.parent.environment;
210207
const packageManager = em.getPackageManager(environment);
211208
await packageManager?.manage(environment, { uninstall: [moduleName], install: [] });
212209
return;
@@ -395,8 +392,17 @@ export async function addPythonProjectCommand(
395392
pc: ProjectCreators,
396393
): Promise<void> {
397394
if (wm.getProjects().length === 0) {
398-
showErrorMessage('Please open a folder/project before adding a workspace');
399-
return;
395+
const r = await showErrorMessage(
396+
'Please open a folder/project to create a Python project.',
397+
{
398+
modal: true,
399+
},
400+
'Open Folder',
401+
);
402+
if (r === 'Open Folder') {
403+
await commands.executeCommand('vscode.openFolder');
404+
return;
405+
}
400406
}
401407
if (resource instanceof Array) {
402408
for (const r of resource) {

0 commit comments

Comments
 (0)