-
Notifications
You must be signed in to change notification settings - Fork 1.2k
getActiveEnvironmentPath
returns incorrect active environment after switching when the Python Environments extension is enabled.
#24953
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@StellaHuang95 I suspect there is some caching somewhere that might be causing this. Is this with Stable or pre-release python extension. |
This is with latest stable python extension. |
Is it possible to switch Pylance extension to use the Python Env extension API for getting Python also? Essentially, if this extension is available then you should use it for all information related to python. Using, both APIs can be problematic. |
The feature I’m implementing is an experimental feature specifically for |
Python extension doesn’t have envs extension as dependency either. It only uses it when it is installed. The API from environment extension is direct. What you could do is check if it is installed, and use that as a signal to consume API from environment extension. |
Sure I can give that a try to see if the problems go away. When you said python extension used envs extension APIs when it's installed, what APIs are you referring to? The getActiveEnvironmentPath() and |
All python related APIs in the python extension uses Python Environments extension when it is installed. I have a check in the implementations where I see if Python Envs extension is installed, if yes then use the Python envs API, else use the legacy API. You should be able to do something similar in the Pylance extension. Here is the code that I use: vscode-python/src/client/envExt/api.internal.ts Lines 20 to 27 in 41e6624
|
Note: This issue only repros when the Python Environments extension is enabled in VS Code.
Repro Steps:
Select Python Interpreter
button on the bottom right corner and switch to a different conda env or venv.Investigation I did:
pythonEnvironmentApi.onDidChangeEnvironment
event and send a custom LSP notification when the event fires.workspace/configuration
request.pythonApi!.environments!.getActiveEnvironmentPath(uri)
andpythonApi!.environments!.resolveEnvironment(activePath)
to get the active Python path.pythonPath
and returns it to the server.I noticed that the env path returned in Step 3 from the python api does not always return the newly selected environment, especially when switching from a global interpreter to a conda one or a workspace venv.
@karthiknadig, do you have any insights on what might be causing this behavior in the Python API?
The text was updated successfully, but these errors were encountered: