feat: add disambiguation suffixes for Python environments in env manager#1197
feat: add disambiguation suffixes for Python environments in env manager#1197eleanorjboyd merged 3 commits intomicrosoft:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds disambiguation suffixes to Python environment tree items when multiple environments share the same base name. The feature helps users distinguish between similarly-named virtual environments (e.g., multiple .venv folders) by displaying their parent folder names in the description field.
Changes:
- Introduced
getEnvironmentParentDirNamefunction to extract parent folder names from environment paths - Added
computeDisambiguationSuffixesto identify environments needing disambiguation and compute their suffixes - Updated
PythonEnvTreeItemto accept and display disambiguation suffixes in the description field
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/features/views/treeViewItems.ts | Added getEnvironmentParentDirName function and updated PythonEnvTreeItem constructor to support disambiguation suffixes |
| src/features/views/envManagersView.ts | Added getBaseName and computeDisambiguationSuffixes functions; integrated disambiguation logic into tree view rendering |
| src/test/features/views/treeViewItems.unit.test.ts | Added comprehensive test coverage for disambiguation suffix functionality and refactored existing tests with helper functions |
| if (part.startsWith('python')) { | ||
| continue; |
There was a problem hiding this comment.
The logic for identifying venv folders relies on checking if a part starts with 'python', but this could incorrectly skip legitimate folder names that start with 'python' (e.g., 'python-utils', 'python_project'). Consider making this check more specific by checking for exact matches with common Python executable names like 'python', 'python3', 'python.exe', etc.
| * @example getBaseName('myenv (3.14.1)') returns 'myenv' | ||
| */ | ||
| function getBaseName(displayName: string): string { | ||
| return displayName.replace(/\s*\([0-9.]+\)\s*$/, '').trim(); |
There was a problem hiding this comment.
The regex pattern [0-9.]+ could match invalid version strings like '3..12' or '...'. Consider using a more precise pattern like [0-9]+(?:\\.[0-9]+)* to match valid semantic version formats.
| return displayName.replace(/\s*\([0-9.]+\)\s*$/, '').trim(); | |
| return displayName.replace(/\s*\([0-9]+(?:\.[0-9]+)*\)\s*$/, '').trim(); |
fixes #1196