Return last-known environment when getEnvironment times out#1607
Merged
Conversation
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
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>
StellaHuang95
approved these changes
Jun 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 whengetEnvironment()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.tscovering the last-known fallback behavior.Notes
Companion to the fast-Pylance-startup work in
microsoft/vscode-pythonand the Pylance server.