Fix: Remove global context that caused "add as Python Project" menu to disappear after single use #724
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.