Skip to content

Prefer using vscode-python-environments’ interpreter change event #1029

Description

@flying-sheep

See “Layer 3” comment here: microsoft/vscode-python-environments#1491 (comment)

When you pick an env via [vscode-python-environments (VPE)]’ tree, we fire pythonEnvsApi.onDidChangeEnvironment (per-workspace). Both ruff-vscode and ty-vscode subscribe only to the legacy api.environments.onDidChangeActiveEnvironmentPath (global only), so they miss our selections — which is exactly why your Select Interpreter workaround "fixes" it (it sets the global env and fires the legacy event). Pylance already supports both APIs: it dual-subscribes, prefers ours when our extension is installed, falls back to the legacy event otherwise. We think that's the right model for ruff/ty too.

IDK how they do it (probably buried in some proprietary pylance code) but I can think of one optimal way:

  1. check if the ms-python.vscode-python-envs extension API can be accessed, if not, load the ms-python.python extension
  2. subscribe to the loaded extensions’ event
  3. subscribe to the extension change event, and when either extension gets disabled, goto 1.

related: #479, astral-sh/ty-vscode#293

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions