From ecf7b6785722529c69b0ca07d8664a41d20d97b2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Jun 2025 20:55:49 +0000 Subject: [PATCH 1/4] Initial plan for issue From 690e15023c2e48d08bf968467bc66db69baa777a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Jun 2025 21:06:36 +0000 Subject: [PATCH 2/4] Remove "Reset to Default" command and UI elements Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com> --- package.json | 17 +++-------------- package.nls.json | 2 +- src/extension.ts | 15 ++++++++++----- src/features/envCommands.ts | 29 +---------------------------- 4 files changed, 15 insertions(+), 48 deletions(-) diff --git a/package.json b/package.json index 4571aa6c..9762f6c5 100644 --- a/package.json +++ b/package.json @@ -160,12 +160,7 @@ "category": "Python", "icon": "$(check)" }, - { - "command": "python-envs.reset", - "title": "%python-envs.reset.title%", - "category": "Python", - "icon": "$(sync)" - }, + { "command": "python-envs.remove", "title": "%python-envs.remove.title%", @@ -276,10 +271,7 @@ "command": "python-envs.setEnv", "when": "false" }, - { - "command": "python-envs.reset", - "when": "false" - }, + { "command": "python-envs.remove", "when": "false" @@ -401,10 +393,7 @@ "group": "inline", "when": "view == python-projects && viewItem =~ /.*python-workspace.*/" }, - { - "command": "python-envs.reset", - "when": "view == python-projects && viewItem =~ /.*python-workspace.*/" - }, + { "command": "python-envs.createTerminal", "group": "inline", diff --git a/package.nls.json b/package.nls.json index 80b8fcf6..95849b72 100644 --- a/package.nls.json +++ b/package.nls.json @@ -22,7 +22,7 @@ "python-envs.createAny.title": "Create Environment", "python-envs.set.title": "Set Project Environment", "python-envs.setEnv.title": "Set As Project Environment", - "python-envs.reset.title": "Reset to Default", + "python-envs.remove.title": "Delete Environment", "python-envs.refreshAllManagers.title": "Refresh All Environment Managers", "python-envs.refreshPackages.title": "Refresh Packages List", diff --git a/src/extension.ts b/src/extension.ts index d87098b9..9217a450 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -32,7 +32,6 @@ import { refreshPackagesCommand, removeEnvironmentCommand, removePythonProject, - resetEnvironmentCommand, runAsTaskCommand, runInDedicatedTerminalCommand, runInTerminalCommand, @@ -61,6 +60,7 @@ import { EnvManagerView } from './features/views/envManagersView'; import { ProjectView } from './features/views/projectView'; import { PythonStatusBarImpl } from './features/views/pythonStatusBar'; import { updateViewsAndStatus } from './features/views/revealHandler'; +import { ProjectItem } from './features/views/treeViewItems'; import { EnvironmentManagers, ProjectCreators, PythonProjectManager } from './internal.api'; import { registerSystemPythonFeatures } from './managers/builtin/main'; import { SysPythonManager } from './managers/builtin/sysPythonManager'; @@ -186,9 +186,7 @@ export async function activate(context: ExtensionContext): Promise { await setEnvironmentCommand(item, envManagers, projectManager); }), - commands.registerCommand('python-envs.reset', async (item) => { - await resetEnvironmentCommand(item, envManagers, projectManager); - }), + commands.registerCommand('python-envs.setEnvManager', async () => { await setEnvManagerCommand(envManagers, projectManager); }), @@ -206,7 +204,14 @@ export async function activate(context: ExtensionContext): Promise { - await resetEnvironmentCommand(item, envManagers, projectManager); + // Clear environment association before removing project + if (item instanceof ProjectItem) { + const uri = item.project.uri; + const manager = envManagers.getEnvironmentManager(uri); + if (manager) { + manager.set(uri, undefined); + } + } await removePythonProject(item, projectManager); }), commands.registerCommand('python-envs.clearCache', async () => { diff --git a/src/features/envCommands.ts b/src/features/envCommands.ts index 55f0acee..ee2cfcf8 100644 --- a/src/features/envCommands.ts +++ b/src/features/envCommands.ts @@ -329,34 +329,7 @@ async function setEnvironmentForProjects( await em.setEnvironments(uris, environment); } -export async function resetEnvironmentCommand( - context: unknown, - em: EnvironmentManagers, - wm: PythonProjectManager, -): Promise { - if (context instanceof ProjectItem) { - const view = context as ProjectItem; - return resetEnvironmentCommand(view.project.uri, em, wm); - } else if (context instanceof Uri) { - const uri = context as Uri; - const manager = em.getEnvironmentManager(uri); - if (manager) { - manager.set(uri, undefined); - } else { - showErrorMessage(`No environment manager found for: ${uri.fsPath}`); - traceError(`No environment manager found for ${uri.fsPath}`); - } - return; - } else if (context === undefined) { - const pw = await pickProject(wm.getProjects()); - if (pw) { - return resetEnvironmentCommand(pw.uri, em, wm); - } - return; - } - traceError(`Invalid context for unset environment command: ${context}`); - showErrorMessage('Invalid context for unset environment'); -} + export async function setEnvManagerCommand(em: EnvironmentManagers, wm: PythonProjectManager): Promise { const projects = await pickProjectMany(wm.getProjects()); From d354864027d81d0abb39c72b2b2ef7dbd8da0198 Mon Sep 17 00:00:00 2001 From: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com> Date: Wed, 11 Jun 2025 15:35:42 -0700 Subject: [PATCH 3/4] add error msg --- src/extension.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/extension.ts b/src/extension.ts index 9217a450..44f97fa0 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -210,6 +210,8 @@ export async function activate(context: ExtensionContext): Promise Date: Fri, 13 Jun 2025 11:25:25 -0700 Subject: [PATCH 4/4] updates for formatting etc --- package.json | 3 --- package.nls.json | 1 - src/extension.ts | 1 - src/features/envCommands.ts | 2 -- 4 files changed, 7 deletions(-) diff --git a/package.json b/package.json index 9762f6c5..f630ca0a 100644 --- a/package.json +++ b/package.json @@ -160,7 +160,6 @@ "category": "Python", "icon": "$(check)" }, - { "command": "python-envs.remove", "title": "%python-envs.remove.title%", @@ -271,7 +270,6 @@ "command": "python-envs.setEnv", "when": "false" }, - { "command": "python-envs.remove", "when": "false" @@ -393,7 +391,6 @@ "group": "inline", "when": "view == python-projects && viewItem =~ /.*python-workspace.*/" }, - { "command": "python-envs.createTerminal", "group": "inline", diff --git a/package.nls.json b/package.nls.json index 95849b72..599f2690 100644 --- a/package.nls.json +++ b/package.nls.json @@ -22,7 +22,6 @@ "python-envs.createAny.title": "Create Environment", "python-envs.set.title": "Set Project Environment", "python-envs.setEnv.title": "Set As Project Environment", - "python-envs.remove.title": "Delete Environment", "python-envs.refreshAllManagers.title": "Refresh All Environment Managers", "python-envs.refreshPackages.title": "Refresh Packages List", diff --git a/src/extension.ts b/src/extension.ts index 44f97fa0..344bf970 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -186,7 +186,6 @@ export async function activate(context: ExtensionContext): Promise { await setEnvironmentCommand(item, envManagers, projectManager); }), - commands.registerCommand('python-envs.setEnvManager', async () => { await setEnvManagerCommand(envManagers, projectManager); }), diff --git a/src/features/envCommands.ts b/src/features/envCommands.ts index ee2cfcf8..cf375d06 100644 --- a/src/features/envCommands.ts +++ b/src/features/envCommands.ts @@ -329,8 +329,6 @@ async function setEnvironmentForProjects( await em.setEnvironments(uris, environment); } - - export async function setEnvManagerCommand(em: EnvironmentManagers, wm: PythonProjectManager): Promise { const projects = await pickProjectMany(wm.getProjects()); if (projects && projects.length > 0) {