Skip to content

Return last-known environment when getEnvironment times out#1607

Merged
rchiodo merged 3 commits into
microsoft:mainfrom
rchiodo:rchiodo-fast-pylance-startup
Jun 24, 2026
Merged

Return last-known environment when getEnvironment times out#1607
rchiodo merged 3 commits into
microsoft:mainfrom
rchiodo:rchiodo-fast-pylance-startup

Conversation

@rchiodo

@rchiodo rchiodo commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Avoid blocking callers of the legacy Python API when an environment can't be resolved quickly during startup/refresh. When getEnvironment() would otherwise wait on an in-progress refresh, return the last-known resolved environment immediately and let the fresh value update afterward.

This is what lets the Python extension's getActiveInterpreter() return within ~100ms during a full environment refresh, so Pylance can start without waiting for enumeration to finish.

Changes

  • features/pythonApi.ts – Track and return the last-known environment when getEnvironment() resolution is slow / times out, rather than blocking on the active refresh.
  • features/envManagers.ts / internal.api.ts – Plumb the last-known environment through the manager/internal API.

Tests

  • src/test/features/envManagers.lastKnown.unit.test.ts covering the last-known fallback behavior.

Notes

Companion to the fast-Pylance-startup work in microsoft/vscode-python and the Pylance server.

Bound EnvironmentManagers.getEnvironment with a timeout so it returns the last-known environment instead of blocking on a full environment refresh. Adds a getLastKnownEnvironment accessor plus unit tests. This keeps Pylance config fetches responsive at startup; the background resolution still completes and fires onDidChangeEnvironment to self-correct.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
StellaHuang95
StellaHuang95 previously approved these changes Jun 24, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Resolve the pythonApi.ts import conflict (keep only the timeout import the
getEnvironment timeout race needs; the rest were duplicates of upstream's
reorganized imports) and adapt getLastKnownEnvironment to upstream's renamed
_activeSelection active-environment cache. Update the last-known unit test to
populate that cache via refreshEnvironment, since upstream's getEnvironment is
now a pure read.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rchiodo rchiodo added the bug Issue identified by VS Code Team member as probable bug label Jun 24, 2026
@rchiodo rchiodo enabled auto-merge (squash) June 24, 2026 18:16
@rchiodo rchiodo merged commit a329c5c into microsoft:main Jun 24, 2026
45 of 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.

2 participants