Commit 664656d
Auto Find: exclude markers inside each workspace folder's selected environment
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`.
```ts
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.
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: edvilme <5952839+edvilme@users.noreply.github.com>sysPrefix (#1843)1 parent 3b85460 commit 664656d
3 files changed
Lines changed: 266 additions & 17 deletions
File tree
- src
- features/creators
- test/features/creators
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
220 | 220 | | |
221 | 221 | | |
222 | 222 | | |
223 | | - | |
| 223 | + | |
224 | 224 | | |
225 | 225 | | |
226 | 226 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | | - | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
63 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
64 | 92 | | |
65 | 93 | | |
66 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
67 | 110 | | |
68 | 111 | | |
69 | 112 | | |
| |||
0 commit comments