Fix #1599: onDidChangePythonProjects never fires on runtime project a… - #1641
Conversation
58e3d18 to
8798be4
Compare
8798be4 to
6b4da73
Compare
| const GET_ENVIRONMENT_TIMED_OUT = Symbol('getEnvironmentTimedOut'); | ||
|
|
||
| class PythonEnvironmentApiImpl implements PythonEnvironmentApi { | ||
| export class PythonEnvironmentApiImpl implements PythonEnvironmentApi { |
There was a problem hiding this comment.
Is there a reason we are exporting this?
There was a problem hiding this comment.
Hi Eduardo Villalpando Mello (@edvilme)! I exported PythonEnvironmentApiImpl so I could import and instantiate it directly in the new unit test file (src/test/features/pythonApi.unit.test.ts) to verify onDidChangePythonProjects. If you prefer a different factory/internal access pattern for unit testing this class, let me know and I'd be happy to adjust!
|
Hello Mohit Yadav (@mohityadav8) thanks for the contribution!! Everything looks great, but there are some linting issues around the use of |
…project add/remove
6b4da73 to
e3184e5
Compare
|
Eduardo Villalpando Mello (@edvilme) thanks for review i have updated my pr now blint check is passing thanks for reviewing this |
There was a problem hiding this comment.
Pull request overview
Fixes PythonEnvironmentApi.onDidChangePythonProjects not firing by wiring the internal project-manager change event through to the public API, computing an { added, removed } delta snapshot-to-snapshot so API consumers (e.g., Pylance) receive runtime project updates.
Changes:
- Subscribes
PythonEnvironmentApiImpltoprojectManager.onDidChangeProjectsand firesonDidChangePythonProjectswith computedadded/removeddeltas. - Tracks a
previousProjectssnapshot to enable delta computation even though the manager emits a full project list. - Adds a unit test validating the public event fires on project changes.
Show a summary per file
| File | Description |
|---|---|
| src/features/pythonApi.ts | Wires internal project changes to the public API event and computes deltas via snapshot diffing. |
| src/test/features/pythonApi.unit.test.ts | Adds unit coverage for onDidChangePythonProjects event forwarding/delta behavior. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 3
- Review effort level: Low
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…github.com/mohityadav8/vscode-python-environments into fix-ondidchange-python-projects-not-firing
|
Eduardo Villalpando Mello (@edvilme) everthing is solved :D |
|
Mohit Yadav (@mohityadav8) could you take a look at the copilot comments- I agree that they are reasonable. Otherwise thanks so much for the contribution! |
Solved copilot review in |
|
Thanks so much for your contribution and fixes. PR looks good to me! :D |
f61acdf
into
microsoft:main
Summary
Fixes #1599 —
PythonEnvironmentApi.onDidChangePythonProjectsnever fired when projects were added or removed at runtime. The internal project list updated correctly, but the public event was never forwarded, so consumers (notably Pylance's per-folder interpreter support) never got notified and required a restart to pick up new projects.Root cause
PythonEnvironmentApiImpl's constructor subscribed to environment-change events but never subscribed toprojectManager.onDidChangeProjects, so_onDidChangePythonProjects.fire(...)was never called.Fix
previousProjectsfield onPythonEnvironmentApiImplthat tracks the last-known project set.projectManager.onDidChangeProjectsin the constructor. On each internal change, compute the added/removed delta by diffing project URIs against the previous snapshot, update the snapshot, and fire_onDidChangePythonProjectswith{ added, removed }when the set actually changed.Diffing by URI (rather than relying on the manager's internal eventpayload) was needed because the manager currently emits the full projectarray rather than a delta, and
DidChangePythonProjectsEventArgsexpectsadded/removed.Testing
npm run compile— clean build.getPythonProjects()that the set updates as expected; confirmed the new subscription fires onaddPythonProject()andremovePythonProject()calls.