Commit 3f33fc2
Fix: Remove global context that caused "add as Python Project" menu to 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>1 parent 796e8cb commit 3f33fc2
File tree
4 files changed
+22
-19
lines changed- src
- features/creators
4 files changed
+22
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
489 | 489 | | |
490 | 490 | | |
491 | 491 | | |
492 | | - | |
| 492 | + | |
493 | 493 | | |
494 | 494 | | |
495 | 495 | | |
496 | 496 | | |
497 | | - | |
| 497 | + | |
498 | 498 | | |
499 | 499 | | |
500 | 500 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | 192 | | |
201 | 193 | | |
202 | 194 | | |
| |||
323 | 315 | | |
324 | 316 | | |
325 | 317 | | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | 318 | | |
332 | 319 | | |
333 | 320 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
87 | 91 | | |
88 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
89 | 97 | | |
90 | 98 | | |
91 | 99 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
60 | 64 | | |
61 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
62 | 70 | | |
63 | 71 | | |
64 | 72 | | |
| |||
0 commit comments