Fix: Remove global context that caused "add as Python Project" menu to disappear after single use#724
Merged
eleanorjboyd merged 6 commits intomainfrom Aug 15, 2025
Merged
Conversation
…e use Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] "add as python project" disappears from menu after single use
Fix: Remove global context that caused "add as Python Project" menu to disappear after single use
Aug 14, 2025
eleanorjboyd
approved these changes
Aug 14, 2025
TylerLeonhardt
approved these changes
Aug 14, 2025
NguyenCuong1989
referenced
this pull request
in NguyenCuong1989/vscode-python-environments
Oct 23, 2025
…o disappear after single use (#724)
The "add as Python Project" context menu item was disappearing after
being used once and only reappearing after a full window reload.
## Root Cause
The issue was caused by improper management of the global VS Code
context `python-envs:isExistingProject`. The context menu visibility was
controlled by the condition:
```json
"when": "explorerViewletVisible && explorerResourceIsFolder && !python-envs:isExistingProject"
```
During command execution, the code would set this global context:
```typescript
commands.executeCommand('setContext', 'python-envs:isExistingProject', isExistingProject(resource));
```
Once this context was set to `true` for any resource, it would prevent
the menu from appearing for all subsequent right-clicks, regardless of
the target folder.
## Solution
- **Removed** the global context setting logic from the
`addPythonProjectGivenResource` command
- **Updated** the context menu conditions in `package.json` to simply
check for folder/file type without the problematic context condition
- **Preserved** existing duplicate detection logic that gracefully
handles attempts to add already-existing projects
The menu will now consistently appear for folders and `.py` files. If
users attempt to add an already-existing project, the existing error
handling shows a "No new projects found" warning.
## Changes
- `src/extension.ts`: Removed context setting logic and unused helper
function (11 lines)
- `package.json`: Simplified context menu conditions (2 lines)
Fixes #723.
<!-- START COPILOT CODING AGENT TIPS -->
---
💬 Share your feedback on Copilot coding agent for the chance to win a
$200 gift card! Click
[here](https://survey.alchemer.com/s3/8343779/Copilot-Coding-agent) to
start the survey.
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The "add as Python Project" context menu item was disappearing after being used once and only reappearing after a full window reload.
Root Cause
The issue was caused by improper management of the global VS Code context
python-envs:isExistingProject. The context menu visibility was controlled by the condition:During command execution, the code would set this global context:
Once this context was set to
truefor any resource, it would prevent the menu from appearing for all subsequent right-clicks, regardless of the target folder.Solution
addPythonProjectGivenResourcecommandpackage.jsonto simply check for folder/file type without the problematic context conditionThe menu will now consistently appear for folders and
.pyfiles. If users attempt to add an already-existing project, the existing error handling shows a "No new projects found" warning.Changes
src/extension.ts: Removed context setting logic and unused helper function (11 lines)package.json: Simplified context menu conditions (2 lines)Fixes #723.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.