Repository navigation
Fire onDidChangeEnvironment when a refresh auto-selects a project venv - #2048
Open
AndreasReichel wants to merge 1 commit into
Open
AndreasReichel wants to merge 1 commit into
AndreasReichel wants to merge 1 commit into
Conversation
When a project has no persisted venv selection, get() returns the global fallback until a refresh finds a venv in the project, e.g. one created after VS Code started. loadEnvMap() then mapped the project to that venv without firing onDidChangeEnvironment, so consumers that cache the interpreter (e.g. Pylint) kept the old one. Fixes microsoft#2046 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
AndreasReichel please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
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.
Fixes #2046
Cause
BuiltInEnvironmentManager.loadEnvMap()runs after every refresh of the venv manager and maps each project to an environment:onDidChangeEnvironmentwhen the environment differs.fsPathToEnv.set().Until then,
get()returns the global fallback for such a project. When a venv is created in the folder while VS Code runs, the next refresh maps the project to it:getEnvironment()switches to the venv, but no manager event fires. BecauserefreshEnvironment()only runs on a manager event, the publiconDidChangeEnvironmentnever fires either. Consumers that cache the interpreter keep the old one; Pylint, for example, keeps linting with the global Python until it is restarted.Fix
In the second case, fire
onDidChangeEnvironmentwhen the picked environment differs from the project's previous entry, or from the global fallback if there was none. The map is cleared at the start ofloadEnvMap(), so its previous entries are copied first.refreshEnvironment()still drops unchanged environments, so refreshes that find the same venv stay quiet.Tests
Two unit tests in
venvManager.autoSelect.unit.test.ts:Also checked by hand with a local build of 1.44.0 plus this change. I opened a folder with only
main.py, ranpython -m venv .venvin it, and compared the logs:onDidChangeEnvironmentafter.venvis discoveredPython 3.14 -> .venv.venvimmediatelySame result with
python.useEnvironmentsExtensionunset, with it set totrue, and withpython-envs.defaultEnvManagerset toms-python.python:venv.🤖 Generated with Claude Code