Skip to content
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

[vscode] Use the python extension venv #820

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

vthemelis
Copy link
Contributor

@vthemelis vthemelis commented Mar 31, 2024

Summary

Fixes #6
Fixes #645
Fixes #183

If the VsCode Python extension is installed, use the Python interpreter that is selected in the extension to start the pyre language server. Also, subscribe to environment switches and restart the pyre language server with the new environments.

If the extension is not present, we retain the original behaviour of the extension.

This is very useful for people that may have multiple environments installed but is more useful for people that use the VsCode SSH extension and cannot benefit from this workaround.

Test Plan

I ran the extension locally and it seems to be picking up the interpreter path.

@vthemelis vthemelis force-pushed the use-vscode-venv branch 2 times, most recently from df8cc87 to 592a3c3 Compare March 31, 2024 00:42
@vthemelis vthemelis changed the title Select the python path of the VSCode venv [vscode] Use activated venv Mar 31, 2024
@@ -34,7 +34,7 @@
"cson": "^4.1.0",
"tslint": "^5.8.0",
"tslint-microsoft-contrib": "^5.0.1",
"typescript": "^2.6.1",
"typescript": "^3.7",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to also add a lock file. This can make it easier to replicate successful builds. I can do this in a separate PR.

@vthemelis vthemelis force-pushed the use-vscode-venv branch 7 times, most recently from 12e1506 to c132e3a Compare March 31, 2024 18:07
@vthemelis
Copy link
Contributor Author

Hi @connernilsen, would it be possible to get a review on this? It's pretty awkward to use the pyre vscode extension without this change.

@connernilsen
Copy link
Contributor

Hey @vthemelis, thanks for the PR! I'm honestly not too familiar with this part of Pyre. Let me see if I can find someone who is more familiar with it and can provide a good review.

@vthemelis vthemelis changed the title [vscode] Use activated venv [vscode] Use the python extension venv Apr 3, 2024
@vthemelis
Copy link
Contributor Author

Thank you very much @connernilsen !

@vthemelis vthemelis force-pushed the use-vscode-venv branch 3 times, most recently from 8322e8f to 5892a19 Compare April 4, 2024 22:57
@vthemelis
Copy link
Contributor Author

Hi guys, can I still get a review for this?

@connernilsen
Copy link
Contributor

Sorry, this fell through the cracks last week. Reaching out to people now.

@vthemelis
Copy link
Contributor Author

thank you! 🙏

@connernilsen
Copy link
Contributor

Alright @vthemelis, thanks for making these changes! The following is a followup that one of my teammates requested:

Would you be able to add a command palette item for allowing changes to this without having to restart VSCode? It looks like the changes here would only work for the initial startup workflow.

@vthemelis
Copy link
Contributor Author

vthemelis commented Apr 16, 2024

Thanks for the review @connernilsen!

There is an event listener that restarts pyre when the user switches environments here

https://github.com/facebook/pyre-check/pull/820/files#diff-1141a7840adc35ecfd0234d6fe8484e7aec33f72306fd32bada0037336ea1f3eR47-R56

Did that not work for you?

I'm happy to also add a palette item as well. Would that be for restarting the Pyre server in the extensions?

@facebook-github-bot
Copy link
Contributor

@kinto0 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@vthemelis
Copy link
Contributor Author

vthemelis commented Apr 22, 2024

Hello @kinto0, thanks for importing the PR! Is there anything I can do to help merge it?

@cclauss
Copy link
Contributor

cclauss commented Apr 24, 2024

For test failures on Python < 3.10 see:

Would this properly address the situation where I pipx install pyre-check ?

@vthemelis
Copy link
Contributor Author

For test failures on Python < 3.10 see:

Thanks, I can merge main into this branch once you merge this PR.

Would this properly address the situation where I pipx install pyre-check ?

I don't think so. It's not really how I use pyre (I install it in my local environment) but can look into this in a separate PR.

@kinto0
Copy link
Contributor

kinto0 commented Apr 29, 2024

sorry about the delay. we had some issues authenticating with the vscode store blocking us from deploying new extensions that should be resolved soon.

Copy link
Contributor

@kinto0 kinto0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you mind taking a look at my error? I see it when testing with or without the python extension enabled

@vthemelis
Copy link
Contributor Author

vthemelis commented Apr 29, 2024

would you mind taking a look at my error? I see it when testing with or without the python extension enabled

Thanks a lot for the review @kinto0 ! I pushed a commit to fix the issue. See: #820 (comment)

@vthemelis
Copy link
Contributor Author

@kinto0, does this work for you now?

@kinto0
Copy link
Contributor

kinto0 commented May 9, 2024

@kinto0, does this work for you now?

did you make a change? I don't see it on my side

@vthemelis
Copy link
Contributor Author

did you make a change? I don't see it on my side

Yes, it's the last commit in the PR. It's also referenced by hash in my reply to your in-line comment.

You may need to import the commit in Phabricator.

Copy link
Contributor

@kinto0 kinto0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left this review after e9147b2 but forgot to publish it... my bad.

const activatedEnvPath = pythonExtension.exports.environments.getActiveEnvironmentPath();
const pyrePath = inferPyreCommand(activatedEnvPath);

if (pyrePath) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if no pyrePath, we should resort to the default one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added an extra case in the findPyreCommand and it now will look in PATH for pyre to use as a fallback.

return {languageClient, configListener};
}

function inferPyreCommand(envPath: EnvironmentPath) : string | undefined {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you rename this findPyreCommand? infer has a connotation of type inference within the codebase

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

tools/ide_plugins/vscode/src/main.ts Show resolved Hide resolved
@vthemelis
Copy link
Contributor Author

@kinto0 , thanks, pushed another commit.

* `s/inferPyre/findPyre/g`
* Use the default pyre command as a fallback if it exists.
@vthemelis
Copy link
Contributor Author

Hi @kinto0 , anything else I can do to help merge this?

@vthemelis
Copy link
Contributor Author

@kinto0 friendly ping :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pyre-vscode doesnt work VSCode + Virtualenv [vscode] "Couldn't start client Pyre Language Client"
5 participants