From 5c34078b94f148fb5172ebf9b154a9d20573f556 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 14 Aug 2025 21:44:52 +0000 Subject: [PATCH 1/5] Initial plan From df57b8cce0352c594cf0215e025d300c0ba9622e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 14 Aug 2025 21:53:23 +0000 Subject: [PATCH 2/5] Fix: Remove global context that caused menu disappearance after single use Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com> --- package.json | 4 ++-- src/extension.ts | 13 ------------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 31887629..4383db75 100644 --- a/package.json +++ b/package.json @@ -489,12 +489,12 @@ { "command": "python-envs.addPythonProjectGivenResource", "group": "inline", - "when": "explorerViewletVisible && explorerResourceIsFolder && !python-envs:isExistingProject" + "when": "explorerViewletVisible && explorerResourceIsFolder" }, { "command": "python-envs.addPythonProjectGivenResource", "group": "inline", - "when": "explorerViewletVisible && resourceExtname == .py && !python-envs:isExistingProject" + "when": "explorerViewletVisible && resourceExtname == .py" } ], "editor/title/run": [ diff --git a/src/extension.ts b/src/extension.ts index c4d89ec8..22b2f658 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -189,14 +189,6 @@ export async function activate(context: ExtensionContext): Promise { - if (!uri) { - return false; - } - return projectManager.get(uri) !== undefined; - }; - const envVarManager: EnvVarManager = new PythonEnvVariableManager(projectManager); context.subscriptions.push(envVarManager); @@ -323,11 +315,6 @@ export async function activate(context: ExtensionContext): Promise { - // Set context to show/hide menu item depending on whether the resource is already a Python project - if (resource instanceof Uri) { - commands.executeCommand('setContext', 'python-envs:isExistingProject', isExistingProject(resource)); - } - await addPythonProjectCommand(resource, projectManager, envManagers, projectCreators); const totalProjectCount = projectManager.getProjects().length + 1; sendTelemetryEvent(EventNames.ADD_PROJECT, undefined, { From ad91e72646894fa634cf7ec1e78b734228b0887f Mon Sep 17 00:00:00 2001 From: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com> Date: Thu, 14 Aug 2025 15:57:47 -0700 Subject: [PATCH 3/5] update warning messaging --- src/features/creators/autoFindProjects.ts | 19 ++++++++++++------- src/features/creators/existingProjects.ts | 12 ++++++++++-- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/features/creators/autoFindProjects.ts b/src/features/creators/autoFindProjects.ts index cb1258e6..e2ef031a 100644 --- a/src/features/creators/autoFindProjects.ts +++ b/src/features/creators/autoFindProjects.ts @@ -70,22 +70,27 @@ export class AutoFindProjects implements PythonProjectCreator { const filtered = files.filter((uri) => { const p = this.pm.get(uri); if (p) { - // Skip this project if: - // 1. There's already a project registered with exactly the same path - // 2. There's already a project registered with this project's parent directory path + // Skip this project if there's already a project registered with exactly the same path const np = path.normalize(p.uri.fsPath); const nf = path.normalize(uri.fsPath); - const nfp = path.dirname(nf); - return np !== nf && np !== nfp; + return np !== nf; } return true; }); if (filtered.length === 0) { // No new projects found that are not already in the project manager - traceInfo('All discovered projects are already registered in the project manager'); + traceInfo( + `All selected resources are already registered in the project manager: ${files + .map((uri) => uri.fsPath) + .join(', ')}`, + ); setImmediate(() => { - showWarningMessage('No new projects found'); + if (files.length === 1) { + showWarningMessage(`${files[0].fsPath} already exists as project.`); + } else { + showWarningMessage('Selected resources already exist as projects.'); + } }); return; } diff --git a/src/features/creators/existingProjects.ts b/src/features/creators/existingProjects.ts index 1bb6ff0c..8f1bef10 100644 --- a/src/features/creators/existingProjects.ts +++ b/src/features/creators/existingProjects.ts @@ -56,9 +56,17 @@ export class ExistingProjects implements PythonProjectCreator { if (filtered.length === 0) { // No new projects found that are not already in the project manager - traceInfo('All discovered projects are already registered in the project manager'); + traceInfo( + `All selected resources are already registered in the project manager: ${existingAddUri + .map((uri) => uri.fsPath) + .join(', ')}`, + ); setImmediate(() => { - showWarningMessage('No new projects found'); + if (existingAddUri.length === 1) { + showWarningMessage(`Selected resource already exists as project.`); + } else { + showWarningMessage('Selected resources already exist as projects.'); + } }); return; } From 4f1b3c1fd03375dfa49dffeedb4221964c5c1f79 Mon Sep 17 00:00:00 2001 From: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com> Date: Thu, 14 Aug 2025 16:01:52 -0700 Subject: [PATCH 4/5] fix linting --- src/features/creators/existingProjects.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/features/creators/existingProjects.ts b/src/features/creators/existingProjects.ts index 8f1bef10..5c66d29b 100644 --- a/src/features/creators/existingProjects.ts +++ b/src/features/creators/existingProjects.ts @@ -56,13 +56,13 @@ export class ExistingProjects implements PythonProjectCreator { if (filtered.length === 0) { // No new projects found that are not already in the project manager + const formattedProjectPaths = + existingAddUri === undefined ? 'None' : existingAddUri.map((uri) => uri.fsPath).join(', '); traceInfo( - `All selected resources are already registered in the project manager: ${existingAddUri - .map((uri) => uri.fsPath) - .join(', ')}`, + `All selected resources are already registered in the project manager. Resources selected: ${formattedProjectPaths}`, ); setImmediate(() => { - if (existingAddUri.length === 1) { + if (existingAddUri && existingAddUri.length === 1) { showWarningMessage(`Selected resource already exists as project.`); } else { showWarningMessage('Selected resources already exist as projects.'); From cdd5cb5fb1b526623ece3f623ced0457e5a0e853 Mon Sep 17 00:00:00 2001 From: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com> Date: Thu, 14 Aug 2025 16:06:05 -0700 Subject: [PATCH 5/5] revert to skip projects with same parent --- src/features/creators/autoFindProjects.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/features/creators/autoFindProjects.ts b/src/features/creators/autoFindProjects.ts index e2ef031a..7d3987c9 100644 --- a/src/features/creators/autoFindProjects.ts +++ b/src/features/creators/autoFindProjects.ts @@ -70,10 +70,13 @@ export class AutoFindProjects implements PythonProjectCreator { const filtered = files.filter((uri) => { const p = this.pm.get(uri); if (p) { - // Skip this project if there's already a project registered with exactly the same path + // Skip this project if: + // 1. There's already a project registered with exactly the same path + // 2. There's already a project registered with this project's parent directory path const np = path.normalize(p.uri.fsPath); const nf = path.normalize(uri.fsPath); - return np !== nf; + const nfp = path.dirname(nf); + return np !== nf && np !== nfp; } return true; });