Dedicated support for the Python Environment Extension#406
Open
MichaReiser wants to merge 15 commits intomainfrom
Open
Dedicated support for the Python Environment Extension#406MichaReiser wants to merge 15 commits intomainfrom
MichaReiser wants to merge 15 commits intomainfrom
Conversation
54db3ed to
780c2d3
Compare
780c2d3 to
20f3125
Compare
MichaReiser
commented
Apr 30, 2026
| let interpreter: string[] = getInterpreterFromSetting(namespace, workspace) ?? []; | ||
| if (interpreter.length === 0) { | ||
| if (vscode.workspace.isTrusted) { | ||
| interpreter = (await getInterpreterDetails(workspace)).path ?? []; |
Member
Author
There was a problem hiding this comment.
We now resolve this during server startup instead of when resolving the setting. This feels more "natural"
MichaReiser
commented
Apr 30, 2026
| ), | ||
| ); | ||
|
|
||
| if (restartInProgress) { |
Member
Author
There was a problem hiding this comment.
activate runs exactly once. It's not clear to me how we would get there with a restart in progress
MichaReiser
commented
Apr 30, 2026
| const environmentProvider = await getEnvironmentProvider(); | ||
|
|
||
| const runServer = async () => { | ||
| if (restartInProgress) { |
Member
Author
There was a problem hiding this comment.
I created a separate restartServer function so that it becomes clearer which work is necessary to serialize restart events.
MichaReiser
commented
May 1, 2026
| import * as util from "node:util"; | ||
| import * as vscode from "vscode"; | ||
|
|
||
| const GROUP_INDENT = " "; |
Member
Author
There was a problem hiding this comment.
The changes here are so that we can have nice logging like this:
2026-05-01 14:42:00.499 [info] Checking whether the active Python environment changes the ty executable.
2026-05-01 14:42:00.548 [info] Resolving active Python environment for workspace: 'file:///Users/micha/astral/test'
2026-05-01 14:42:00.548 [info] Resolved Python executable for ty lookup: '/Users/micha/astral/test/.venv/bin/python'
2026-05-01 14:42:00.575 [info] Resolved ty executable from Python environment: '/Users/micha/astral/test/.venv/bin/ty'
2026-05-01 14:42:00.576 [info] Resolved ty executable changed from '/Users/micha/astral/ty-vscode/bundled/libs/bin/ty' to '/Users/micha/astral/test/.venv/bin/ty'; restarting ty.
This matches the console.group and console.groupEnd APIs
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
This PR adds dedicated support for the Python Environment extension.
There are three operations for which we integrate with the Python extension and the Python Environment extension:
However, the way our code is structured today didn't make this very clear. Which ultimately resulted in a couple of refactors:
EnvironmentProviderinterface to abstract over different environment providers. For now, there's an implementation for both the Python Extension and the Python Environment extension, but I foresee a third implementation that uses the bundled ty bundle (or uv!) to find the virtual environment.onDidActiveEnvironmentChangeevent, which resulted in a lot of unnecessary server restarts. That's why I decided to beef up our server restart logic to avoid restarts unless the environment change results in the extension picking up a differenttybinary or the environment actually changed.ty.interpreterfromstring[]tostring. We always ignored all paths except the first. Making this astringis more honest.It should be possible to split some of those changes into separate PRs, but I didn't do so because all of them were motivated by getting to a working Python Environment extension integration.
Don't worry, you don't need to review 2k lines. About 1400 lines are from the Python Environment extension's type definitions.
Fixes astral-sh/ty#3021
Test Plan
I tested
ty.interpreteris setty.pathis set