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

Add "Default" LS setting, which picks between Jedi/Pylance #16139

Conversation

jakebailey
Copy link
Member

@jakebailey jakebailey commented May 4, 2021

Adds a new "Default" setting, which implies Pylance when Pylance installed, otherwise uses jedi (plus/minus the LSP experiment).

For https://github.com/microsoft/vscode-python-internalbacklog/issues/176.

@jakebailey jakebailey requested a review from kimadeline May 4, 2021 20:31
"Jedi",
"JediLSP",
"Pylance",
"Microsoft",
"None"
],
"default": "Jedi",
"default": "Default",
Copy link
Member Author

Choose a reason for hiding this comment

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

Should I remove this change now?

Choose a reason for hiding this comment

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

Seems fine for now, why do you think this needs to be removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

This one can probably stay regardless, but the other code makes Pylance the default (and IDK when we want to actually flip that switch; this PR or another.

Copy link

@kimadeline kimadeline May 4, 2021

Choose a reason for hiding this comment

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

I think we'll be fine; hopefully #16069 will be merged before this one, we can then merge default-language-server in main (PR here), and then when this PR makes it in default-language-server we can hold off on merging it in main again until we're good to go.

@@ -1225,13 +1225,14 @@
"python.languageServer": {
"type": "string",
"enum": [
"Default",
Copy link
Member Author

Choose a reason for hiding this comment

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

I think this block could use an enumDescriptions to define the semantics of each of these.

Choose a reason for hiding this comment

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

Here you go: #16141

@@ -167,7 +167,7 @@ export class PythonSettings implements IPythonSettings {
private readonly experimentsManager?: IExperimentsManager,
private readonly interpreterPathService?: IInterpreterPathService,
private readonly interpreterSecurityService?: IInterpreterSecurityService,
private readonly defaultJedi?: IDefaultLanguageServer,
private readonly defaultLS?: IDefaultLanguageServer,
Copy link
Member Author

Choose a reason for hiding this comment

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

The meaning of IDefaultLanguageServer has changed to return what "Default" will mean; before it also checked the user's settings, which was too much. This file is what actually determines the final result.

userLS === 'Default' ||
!Object.values(LanguageServerType).includes(userLS as LanguageServerType)
) {
ls = this.defaultLS?.defaultLSType ?? LanguageServerType.Jedi;
Copy link
Member Author

Choose a reason for hiding this comment

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

defaultLS can be undefined, so I had to hardcode some default here, but I'm honestly not sure under which conditions this can be the case.

Choose a reason for hiding this comment

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

Since you removed the condition in setDefaultLanguageServer I don't see why it would ever be undefined either, unless this instance gets added before setDefaultLanguageServer is called?

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried making it required, and hit a bunch of places that simply don't have access to the data needed, so IDK what's going on there.

experimentService: IExperimentService,
extensions: IExtensions,
): Promise<PotentialDefault> {
if (extensions.getExtension<ILSExtensionApi>(PYLANCE_EXTENSION_ID)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I would have liked to call activate here and figure out of Pylance is functional or not, but Pylance hard deps on Python, and this means that activate will block forever due to the cycle.

We'll have to rely on later checks to fallback to Jedi.

@github-actions github-actions bot requested a review from karrtikr May 4, 2021 21:13
@jakebailey jakebailey changed the title Bundle Pylance as part of an extension pack (not a hard dependency) (#16077) Bundle Pylance as part of an extension pack (not a hard dependency) May 4, 2021
"Jedi",
"JediLSP",
"Pylance",
"Microsoft",
"None"
],
"default": "Jedi",
"default": "Default",

Choose a reason for hiding this comment

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

Seems fine for now, why do you think this needs to be removed?

@kimadeline kimadeline added skip package*.json package.json and package-lock.json don't both need updating no-changelog No news entry required labels May 4, 2021
@kimadeline
Copy link

Added @karthiknadig because he did the JediLSP work

@jakebailey
Copy link
Member Author

We'll probably want to change

if (serverType === LanguageServerType.JediLSP && interpreter && interpreter.version) {
if (interpreter.version.major < 3 || (interpreter.version.major === 3 && interpreter.version.minor < 6)) {
sendTelemetryEvent(EventName.JEDI_FALLBACK);
serverType = LanguageServerType.Jedi;
}
}
to also do the check for Pylance, since we don't do python 2 either... But I'll have to check the implications of this because I hacked the refcounting system to only have one instance of pylance at any given time.

Is Python 2 going away anytime soon? :)

@jakebailey jakebailey changed the title Bundle Pylance as part of an extension pack (not a hard dependency) Add "Default" LS setting, which picks between Jedi/Pylance May 5, 2021
@jakebailey
Copy link
Member Author

Fixed the title; no idea why it did that.

@kimadeline kimadeline closed this May 5, 2021
@kimadeline kimadeline deleted the branch microsoft:default-language-server May 5, 2021 18:28
@kimadeline
Copy link

What happened

@jakebailey
Copy link
Member Author

GH really did not like that. I'll have to rebase and resend.

Copy link

@karrtikr karrtikr left a comment

Choose a reason for hiding this comment

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

LGTM otherwise.

if (
!userLS ||
userLS === 'Default' ||
!Object.values(LanguageServerType).includes(userLS as LanguageServerType)
Copy link

Choose a reason for hiding this comment

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

Not sure what this condition signifies. Does this mean if user has selected an invalid LS value, we select the default LS in those cases?

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct. We can't trust user values from enums, so this checks for invalid ones and then selects the default if they are present. That's sort of the problem with the VS code settings API; it's too easy to make mistakes.

import { ILSExtensionApi } from '../node/languageServerFolderService';
import { LanguageServerType } from '../types';

export type PotentialDefault = LanguageServerType.Jedi | LanguageServerType.JediLSP | LanguageServerType.Node;
Copy link

Choose a reason for hiding this comment

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

Need not be exported.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch; this should be with IDefaultLanguageServer.

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 skip package*.json package.json and package-lock.json don't both need updating
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants