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

Make it possible to use the LSP to talk to Jedi #13855

Merged
merged 18 commits into from
Sep 11, 2020
Merged

Make it possible to use the LSP to talk to Jedi #13855

merged 18 commits into from
Sep 11, 2020

Conversation

rchiodo
Copy link

@rchiodo rchiodo commented Sep 9, 2020

For #11995

This is the beginning of the work to switch to the Jedi LSP. It installs a fork of https://github.com/pappasam/jedi-language-server and sets up an experiment to control whether or not to use it.

Still left to do:

The goal here is to submit this and then split up the work of fixing the bugs in our fork and then push the changes the original pappasam main fork.

I forked it here: https://github.com/vscode-python/jedi-language-server

python-jsonrpc-server==0.2.0 \
--hash=sha256:59ce9c9523c14c493a327b3a27ee37464a36dc2b9d8ab485ecbcedd38840380a \
# via -r requirements.in
click==7.1.2 # via jedi-language-server
Copy link
Author

Choose a reason for hiding this comment

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

Hashes don't seem to work with git hub dependencies. At least I haven't figured out how to make them work. Still looking into it.

package.json Outdated
"All"
]
},
"description": "List of experiment to opt into. If empty, user is assigned the default experiment groups. See https://github.com/microsoft/vscode-python/wiki/Experiments for more details.",
"scope": "machine"
"scope": "resource"

Choose a reason for hiding this comment

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

These need to be per machine, we cannot have user opt into an experiment in one workspace & not the other.

Copy link
Author

Choose a reason for hiding this comment

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

Why not?

Copy link
Author

Choose a reason for hiding this comment

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

This is required to get the tests to pass. Otherwise I have to do something like write the global settings.json or create an environment variable that overrides this in the actual source code.

Copy link
Author

Choose a reason for hiding this comment

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

Is this only a problem in multiple workspaces?

Choose a reason for hiding this comment

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

If the requirement is to get the tests to pass, then you can easily update this package.json during tests (that's what I do in native notebooks), i.e. in tests update the scope.
Else we're changing functionality of the product here, just for tests to pass, & i don' think that's the right thing.

Example:

  • User opts into experiment that deprecate pythonPath setting,
  • User opens another worksapce, now VS Code will complainin about python path not being setup

I.e. our code needs to be written in such a way that experiments are scoped to a workspace instance & not global. Today we assume that user is in experiment. We don't assume that an instance of vs code is in an experiment.

Choose a reason for hiding this comment

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

If we want to change this behavior thats fine, i'd leave this for core team to decide.

Copy link
Author

Choose a reason for hiding this comment

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

Okay I put it back. Test startup code writes the package.json now.

package.json Outdated
"All"
]
},
"description": "List of experiment to opt out of. If empty, user is assigned the default experiment groups. See https://github.com/microsoft/vscode-python/wiki/Experiments for more details.",
"scope": "machine"
"scope": "resource"

Choose a reason for hiding this comment

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

See previous comment.

@codecov-commenter
Copy link

codecov-commenter commented Sep 9, 2020

Codecov Report

Merging #13855 into main will decrease coverage by 0.21%.
The diff coverage is 31.07%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #13855      +/-   ##
==========================================
- Coverage   60.03%   59.82%   -0.22%     
==========================================
  Files         685      691       +6     
  Lines       38086    38337     +251     
  Branches     5487     5515      +28     
==========================================
+ Hits        22866    22934      +68     
- Misses      14039    14219     +180     
- Partials     1181     1184       +3     
Impacted Files Coverage Δ
src/client/activation/common/cancellationUtils.ts 13.95% <ø> (ø)
...rc/client/activation/node/languageClientFactory.ts 36.36% <ø> (ø)
...rc/client/activation/jedi/multiplexingActivator.ts 17.74% <17.74%> (ø)
src/client/activation/jedi/languageServerProxy.ts 27.27% <27.27%> (ø)
src/client/activation/jedi/manager.ts 30.30% <30.30%> (ø)
...rc/client/activation/jedi/languageClientFactory.ts 40.00% <40.00%> (ø)
src/client/activation/serviceRegistry.ts 77.27% <45.45%> (-5.01%) ⬇️
src/client/activation/jedi/activator.ts 70.00% <70.00%> (ø)
src/client/activation/jedi/analysisOptions.ts 71.42% <71.42%> (ø)
src/client/activation/node/languageServerProxy.ts 26.58% <100.00%> (ø)
... and 14 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0bcc807...74bf550. Read the comment docs.

Copy link

@DonJayamanne DonJayamanne left a comment

Choose a reason for hiding this comment

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

I think the changes to the scope are leftovers of the tests

const jediServerModulePath = path.join(EXTENSION_ROOT_DIR, 'pythonFiles', 'runJediLanguageServer.py');
const interpreter = await this.interpreterService.getActiveInterpreter(resource);
const pythonPath = interpreter ? interpreter.path : 'python';
const args = [`${jediServerModulePath}`];

Choose a reason for hiding this comment

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

Suggested change
const args = [`${jediServerModulePath}`];
const args = [jediServerModulePath];

Copy link
Author

Choose a reason for hiding this comment

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

Yes that was silly. I was original putting quotes around it, but not necessary.

"noFallthroughCasesInSwitch": true
"noFallthroughCasesInSwitch": true,
"resolveJsonModule": true,
"removeComments": true

Choose a reason for hiding this comment

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

Why are we removing the comments?

Copy link
Author

Choose a reason for hiding this comment

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

So I can import json with comments. Didn't think comments were necessary and it makes reading the settings.json super simple.

@@ -99,6 +99,10 @@ export enum SurveyAndInterpreterTipNotification {
surveyExperiment = 'pythonMailingListPromptWording'
}

// Experiment to switch Jedi to use an LSP instead of direct providers
export enum JediLSP {
experiment = 'jediLSP'

Choose a reason for hiding this comment

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

Do we need seprate Enums?
I'm not sure why we ended up creating 1 enum for each experiment.
Why not create an enum named Experiments and we always use that single enum. Then its strongly typed as well, rather than just accepting strings.

Choose a reason for hiding this comment

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

FYI - I know this is how the old stuff has been written, just never understand why, its more stuff that needs to be imported & the experiments are not strongly typed (as we just accept strings, & we need to dig around to find the right enum).

Copy link
Author

Choose a reason for hiding this comment

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

Yeah I'm not going to change it now. We can enter an issue if you want to refactor this stuff.

@rchiodo rchiodo requested a review from DonJayamanne September 9, 2020 22:51
@brettcannon brettcannon removed their request for review September 10, 2020 16:19
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@rchiodo
Copy link
Author

rchiodo commented Sep 10, 2020

@karthiknadig can you take a look when you get the chance? Thanks


# Trick language server into thinking it started from 'jedi-language-server.exe'
sys.argv[0] = "jedi-language-server.exe"
sys.exit(cli())
Copy link
Member

Choose a reason for hiding this comment

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

We should file this as a bug. We should be able to run this python EXTENSION_ROOT/pythonFiles/lib/python the same way we run debugpy. We won't need this file.

Copy link
Author

Choose a reason for hiding this comment

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

I think this is particular to how we're installing it. If you pip install it, it generates an exe in your scripts folder that you would normally use (that exe has this exact code in it)

Copy link
Member

Choose a reason for hiding this comment

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

This script does not restrict running this only to windows. So argv[0] will be wrong for linux/mac. The problem is in the package itself. You should be able to just run via __main__.py in that package. This is a fairly small change, and it preservers existing functionality. Secondly, the package itself won;t require installation to run. since we don;t want to install this for each python environment.

Copy link
Author

Choose a reason for hiding this comment

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

Oh there is no __main__.py in the package. So maybe adding that would fix the problem?

Copy link
Author

Choose a reason for hiding this comment

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

We don't install this for every environment. We run it like we ran jedi. It ships as part of the VSIX.

Copy link
Member

Choose a reason for hiding this comment

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

Yep, it is a simple enough fix. We can take that later. For now lets get this working.

Copy link
Member

Choose a reason for hiding this comment

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

I know we don;t install for every environment. My point was that the package is designed in a way where it expects that. Hence you had to add this script to run it. But really it should not require installation nor should it require this script. The problem is with the packaging.

@rchiodo rchiodo merged commit ed3f29f into main Sep 11, 2020
@rchiodo rchiodo deleted the rchiodo/jedi_lsp branch September 11, 2020 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog No news entry required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants