Repository navigation
Fix global interpreter selection readback routing (#1922) - #1924
Aadi Jain (Thrizzio) wants to merge 4 commits into
Conversation
Prefer cached global environment manager over default manager when resolving global context. Ensure getEnvironment(undefined) and Python Projects sidebar reflect cross-manager selections. Add regression test for cross-manager global selection.
|
@microsoft-github-policy-service agree |
|
Hi Bill Schnurr (@bschnurr), Eduardo Villalpando Mello (@edvilme), and Rich Chiodo (@rchiodo), I've opened this PR to address #1922. The fix addresses global interpreter selection readback when the selected environment belongs to a different manager than the configured default. I've added regression coverage and run the unit tests, compilation, lint, and diff checks. I've also manually tested the selection flow in an empty VS Code window. If screenshots or a short recording of the manual verification would be helpful, I'm happy to add them. Thank you for your time! |
|
ok |
Eduardo Villalpando Mello (edvilme)
left a comment
There was a problem hiding this comment.
Thx for the contribution, and sorry it took us a bit to review.
Fix looks good but left a comment that I think could improve it :)
There was a problem hiding this comment.
I think you could extract the cachedEnv variable to avoid having to reset it twice
const cachedEnv = this._activeSelection.get(this.getProjectSelectionKey(project));
const cachedManager = cachedEnv
? this._environmentManagers.get(cachedEnv.envId.managerId)
: undefined;
if (context == undefined && cachedManager) {
return cachedManager;
}
// Default env manager, etc...
if (cachedManager) {
return cachedManager;
}There was a problem hiding this comment.
Updated to extract cachedEnv and cachedManager upfront as suggested. Tests and linter are passing. Thanks!
Summary
Fixes #1922
Fixes inconsistent global Python interpreter selection readback when the selected interpreter belongs to a different environment manager than the configured default.
In an empty VS Code window, selecting a non-venv interpreter (e.g. system or Conda) while
ms-python.python:venvis the configured default could cause subsequent calls togetEnvironmentManager(undefined)andgetEnvironment(undefined)to resolve through the venv manager instead of the manager associated with the selected environment.Root Cause
Global interpreter selections are cached in
_activeSelectionunder the global selection key. However,getConfiguredOrCachedEnvironmentManager()previously preferred the configured default manager over the manager associated with the cached global selection.As a result, the configured default manager took precedence during subsequent global environment readback, even when the active selection belonged to another manager.
Changes
src/features/envManagers.ts:context === undefined), provided that manager is registered.getEnvironment(undefined)without writing manager defaults into User Settings.src/test/features/envManagers.unit.test.ts:ms-python.python:venv.getEnvironment(undefined)use the selected system interpreter's manager rather than the configured venv manager.Related Issues (Context Only)
Verification
2842 passing, 12 pending, 0 failing).npm run compile-tests && npm run unittest(Pass)npm run compile(Pass)npm run lint(Pass)git diff --check(Pass)Python Projects > Globalsidebar view and subsequent readbacks immediately synchronize with the chosen environment.