Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 14, 2025

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:

"when": "explorerViewletVisible && explorerResourceIsFolder && !python-envs:isExistingProject"

During command execution, the code would set this global context:

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.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

…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
Copilot AI requested a review from eleanorjboyd August 14, 2025 21:56
Copilot finished work on behalf of eleanorjboyd August 14, 2025 21:56
@eleanorjboyd eleanorjboyd marked this pull request as ready for review August 14, 2025 23:02
@vs-code-engineering vs-code-engineering bot added this to the August 2025 milestone Aug 14, 2025
@eleanorjboyd eleanorjboyd merged commit 3f33fc2 into main Aug 15, 2025
10 checks passed
@eleanorjboyd eleanorjboyd deleted the copilot/fix-723 branch August 15, 2025 16:31
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"add as python project" disappears from menu after single use

3 participants