Skip to content

Fix #1599: onDidChangePythonProjects never fires on runtime project a… - #1641

Merged
Eduardo Villalpando Mello (edvilme) merged 4 commits into
microsoft:mainfrom
mohityadav8:fix-ondidchange-python-projects-not-firing
Jul 24, 2026
Merged

Fix #1599: onDidChangePythonProjects never fires on runtime project a…#1641
Eduardo Villalpando Mello (edvilme) merged 4 commits into
microsoft:mainfrom
mohityadav8:fix-ondidchange-python-projects-not-firing

Conversation

@mohityadav8

@mohityadav8 Mohit Yadav (mohityadav8) commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #1599PythonEnvironmentApi.onDidChangePythonProjects never 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

  • Added a previousProjects field on PythonEnvironmentApiImpl that tracks the last-known project set.
  • Subscribed to projectManager.onDidChangeProjects in the constructor. On each internal change, compute the added/removed delta by diffing project URIs against the previous snapshot, update the snapshot, and fire _onDidChangePythonProjects with { 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 DidChangePythonProjectsEventArgs expectsadded/removed.

Testing

  • npm run compile — clean build.
  • Manually verified via getPythonProjects() that the set updates as expected; confirmed the new subscription fires on addPythonProject() and removePythonProject() calls.

@mohityadav8

Copy link
Copy Markdown
Contributor Author

cc Eleanor Boyd (@eleanorjboyd)

Comment thread src/features/pythonApi.ts
const GET_ENVIRONMENT_TIMED_OUT = Symbol('getEnvironmentTimedOut');

class PythonEnvironmentApiImpl implements PythonEnvironmentApi {
export class PythonEnvironmentApiImpl implements PythonEnvironmentApi {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we are exporting this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@edvilme Eduardo Villalpando Mello (edvilme) added the bug Issue identified by VS Code Team member as probable bug label Jul 22, 2026
@edvilme

Copy link
Copy Markdown
Contributor

Hello Mohit Yadav (@mohityadav8) thanks for the contribution!! Everything looks great, but there are some linting issues around the use of any in TS. Once they get fixed, we can merge this! 😄

@mohityadav8
Mohit Yadav (mohityadav8) force-pushed the fix-ondidchange-python-projects-not-firing branch from 6b4da73 to e3184e5 Compare July 23, 2026 09:44
@mohityadav8

Copy link
Copy Markdown
Contributor Author

Eduardo Villalpando Mello (@edvilme) thanks for review i have updated my pr now blint check is passing thanks for reviewing this

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 PythonEnvironmentApiImpl to projectManager.onDidChangeProjects and fires onDidChangePythonProjects with computed added/removed deltas.
  • Tracks a previousProjects snapshot 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

Comment thread src/features/pythonApi.ts
Comment thread src/test/features/pythonApi.unit.test.ts Outdated
Comment thread src/test/features/pythonApi.unit.test.ts
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@mohityadav8

Copy link
Copy Markdown
Contributor Author

Eduardo Villalpando Mello (@edvilme) everthing is solved :D

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@eleanorjboyd

Copy link
Copy Markdown
Member

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!

@mohityadav8

Copy link
Copy Markdown
Contributor Author

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 e14f6e4

@edvilme

Copy link
Copy Markdown
Contributor

Thanks so much for your contribution and fixes. PR looks good to me! :D

@edvilme
Eduardo Villalpando Mello (edvilme) merged commit f61acdf into microsoft:main Jul 24, 2026
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issue identified by VS Code Team member as probable bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Public onDidChangePythonProjects API event never fires (runtime project add/remove not reported to consumers)

5 participants