Skip to content

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

Open
mohityadav8 wants to merge 1 commit into
microsoft:mainfrom
mohityadav8:fix-ondidchange-python-projects-not-firing
Open

Fix #1599: onDidChangePythonProjects never fires on runtime project a…#1641
mohityadav8 wants to merge 1 commit into
microsoft:mainfrom
mohityadav8:fix-ondidchange-python-projects-not-firing

Conversation

@mohityadav8

@mohityadav8 mohityadav8 commented Jul 19, 2026

Copy link
Copy Markdown

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
mohityadav8 force-pushed the fix-ondidchange-python-projects-not-firing branch from 8798be4 to 6b4da73 Compare July 22, 2026 20:07
@mohityadav8

Copy link
Copy Markdown
Author

cc @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?

@edvilme edvilme added the bug Issue identified by VS Code Team member as probable bug label Jul 22, 2026
@edvilme

edvilme commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Hello @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! 😄

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)

2 participants