Skip to content

Auto Find: exclude markers inside each workspace folder's selected environment sysPrefix - #1843

Merged
Eduardo Villalpando Mello (edvilme) merged 8 commits into
mainfrom
copilot/fix-auto-find-projects
Sep 30, 2026
Merged

Eduardo Villalpando Mello (edvilme) merged 8 commits into
mainfrom
copilot/fix-auto-find-projects

Conversation

Copilot AI commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #406

Auto Find searches for pyproject.toml and setup.py but excludes only **/.venv/**. As a result, packages installed in a selected environment with any other directory name (for example custom-env/lib/.../site-packages/pkg/setup.py) are offered as projects. This PR drops those false positives using the sysPrefix of the environment selected for each workspace folder.

Changes

  • AutoFindProjects (src/features/creators/autoFindProjects.ts)
    • Takes EnvironmentManagers as a new constructor dependency.
    • After findFiles returns results, calls envManagers.getEnvironment(folder.uri) once for each folder in getWorkspaceFolders(). Only non-empty, absolute sysPrefix values are kept.
    • Drops markers at or below any of those prefixes using the existing isSameOrParentPath, which already enforces path boundaries and handles Windows case and separators.
    • The filter runs before the "No projects found" and "already registered" checks. If every match is inside an environment, the user sees "No projects found", not a misleading "already exists as project" warning.
    • A lookup failure is logged with traceWarn and that folder is skipped; discovery continues.
  • Wiring (src/extension.ts): passes the existing envManagers instance to AutoFindProjects.
const found = await findFiles('**/{pyproject.toml,setup.py}', '**/.venv/**');
const prefixes = found && found.length > 0 ? await this.getSelectedEnvironmentPrefixes() : [];
const files = found?.filter((uri) => !prefixes.some((prefix) => isSameOrParentPath(prefix, uri.fsPath)));

Unchanged

  • **/.venv/** exclusion, picker, de-duplication and registration.
  • With no selected environment or no usable prefix, behaviour is the same as before.

Out of scope

  • Inactive, unselected or global environments.
  • Environments selected for nested projects.
  • Symlinked environment paths.
  • Environment refreshes, caches or watchers.
  • Settings or API changes.
  • Add Existing.

An environment that is not the selected one for any workspace folder is still excluded only if it is named .venv.

Tests (autoFindProjects.unit.test.ts)

  • Constructor mocks updated.
  • A custom-env selected environment excludes both marker types, including a marker at the environment root. A real project next to it and a similarly named sibling custom-env-project are still offered.
  • With two workspace folders, each folder's prefix is applied separately (one lookup per folder).
  • An undefined prefix, a relative prefix and a thrown lookup each leave existing behaviour unchanged.
  • When every marker is inside an environment, "No projects found" is shown with no picker, warning or registration.

…ry (#406)

Co-authored-by: edvilme <5952839+edvilme@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix auto find projects to exclude false positives in workspace environments Auto Find: exclude markers inside each workspace folder's selected environment sysPrefix Sep 30, 2026
@edvilme Eduardo Villalpando Mello (edvilme) added the bug Issue identified by VS Code Team member as probable bug label Sep 30, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation matches the stated scope and includes appropriate cross-platform tests and failure handling.

Review effort: Balanced
Findings: None

What changed in this PR

Excludes project markers located inside selected workspace environments, preventing installed packages from appearing as projects.

Changes:

  • Filters markers using each selected environment’s absolute sysPrefix.
  • Continues discovery when environment lookup fails.
  • Adds cross-platform unit coverage and dependency wiring.
File Description
src/​features/​creators/​autoFindProjects.ts Adds environment-prefix filtering.
src/​extension.ts Injects environment managers.
src/​test/​features/​creators/​autoFindProjects.unit.test.ts Tests filtering and fallback behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filter assumes everything beneath an environment’s sysPrefix is an environment artifact. For system Python with sysPrefix = /usr, a legitimate workspace at /usr/src/app loses every project marker.

const prefixes = found && found.length > 0 ? await this.getSelectedEnvironmentPrefixes() : [];

@edvilme

Copy link
Copy Markdown
Contributor

The filter assumes everything beneath an environment’s sysPrefix is an environment artifact. For system Python with sysPrefix = /usr, a legitimate workspace at /usr/src/app loses every project marker.

Copilot address the issue of potential false positives, maybe get the environment object and extract metadata from there first?

Co-authored-by: edvilme <5952839+edvilme@users.noreply.github.com>
@edvilme
Eduardo Villalpando Mello (edvilme) marked this pull request as ready for review September 30, 2026 16:42
Co-authored-by: edvilme <5952839+edvilme@users.noreply.github.com>
Copilot AI and others added 3 commits September 30, 2026 16:52
Co-authored-by: edvilme <5952839+edvilme@users.noreply.github.com>
Co-authored-by: edvilme <5952839+edvilme@users.noreply.github.com>
Co-authored-by: edvilme <5952839+edvilme@users.noreply.github.com>

Copilot AI commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

The filter assumes everything beneath an environment’s sysPrefix is an environment artifact. For system Python with sysPrefix = /usr, a legitimate workspace at /usr/src/app loses every project mar...

Addressed in 6b0b889. Auto Find now checks the selected environment’s manager ID and prefix location: broad prefixes cannot hide workspace projects, while system-managed interpreters only exclude installed-package markers (site-packages/dist-packages). Workspace-local environments still filter their package markers, including when resolved by the system manager. Added regression tests for broad, nested, and cross-root workspaces.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

System-manager-resolved and workspace-root environments can still expose installed-package markers.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)

Co-authored-by: edvilme <5952839+edvilme@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The filtering logic is cross-platform, safely handles lookup failures and broad prefixes, and is comprehensively tested.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@rchiodo

Rich Chiodo (rchiodo) commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

🔒 Automated review in progress — Rich Chiodo (@rchiodo) is auto-reviewing this PR.

(folder) =>
isSameOrParentPath(prefix, folder.uri.fsPath) &&
isSameOrParentPath(folder.uri.fsPath, uri.fsPath),
),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning · Non-blocking recommendation

When a workspace folder equals its selected environment prefix, this exception preserves every marker below it, including site-packages/pkg/setup.py. Apply the broad exception only when the workspace is strictly below the prefix; for equality, preserve only a marker at the workspace root, and add a test covering a nested installed package.

@rchiodo

Copy link
Copy Markdown
Contributor

Result: 🔴 could-not-verify

Verification details

Verification: The relevant tests could not be fully run in the isolated environment; this review is not fully verified.

Summary: [unavailable] Container verification could not start and local execution was not authorized for this PR HEAD: Podman machine &#x27;pyrx-automation&#x27; is not running.

Test runs: none recorded.

@rchiodo Rich Chiodo (rchiodo) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved via Review Center.

@rchiodo Rich Chiodo (rchiodo) added the review-auto:approved Automated review: no blocking findings (approval posted). label Sep 30, 2026
@edvilme
Eduardo Villalpando Mello (edvilme) merged commit 664656d into main Sep 30, 2026
100 of 101 checks passed
@edvilme
Eduardo Villalpando Mello (edvilme) deleted the copilot/fix-auto-find-projects branch September 30, 2026 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issue identified by VS Code Team member as probable bug review-auto:approved Automated review: no blocking findings (approval posted).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use the Prefix path for the environment when autofinding projects

5 participants