Skip to content

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

Closed
Jake Bailey (jakebailey) wants to merge 5 commits into
microsoft:default-language-serverfrom
jakebailey:new-default-ls-setting
Closed

Add "Default" LS setting, which picks between Jedi/Pylance#16139
Jake Bailey (jakebailey) wants to merge 5 commits into
microsoft:default-language-serverfrom
jakebailey:new-default-ls-setting

Conversation

@jakebailey

@jakebailey Jake Bailey (jakebailey) commented May 4, 2021

Copy link
Copy Markdown
Member

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.

Comment thread package.json
"None"
],
"default": "Jedi",
"default": "Default",

Copy link
Copy Markdown
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
Copy Markdown
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.

@kimadeline Kim-Adeline Miguel (kimadeline) May 4, 2021

Copy link
Copy Markdown

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.

Comment thread package.json
"python.languageServer": {
"type": "string",
"enum": [
"Default",

Copy link
Copy Markdown
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

private readonly interpreterPathService?: IInterpreterPathService,
private readonly interpreterSecurityService?: IInterpreterSecurityService,
private readonly defaultJedi?: IDefaultLanguageServer,
private readonly defaultLS?: IDefaultLanguageServer,

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

@jakebailey Jake Bailey (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
Comment thread src/client/activation/common/defaultlanguageServer.ts
Comment thread package.json
"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 Kim-Adeline Miguel (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
Copy Markdown

Added Karthik Nadig (@karthiknadig) because he did the JediLSP work

@jakebailey

Copy link
Copy Markdown
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 Jake Bailey (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
Copy Markdown
Member Author

Fixed the title; no idea why it did that.

@kimadeline
Kim-Adeline Miguel (kimadeline) deleted the branch microsoft:default-language-server May 5, 2021 18:28
@kimadeline

Copy link
Copy Markdown

What happened

@jakebailey

Copy link
Copy Markdown
Member Author

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

@karrtikr Kartik Raj (karrtikr) left a comment

Copy link
Copy Markdown

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
Copy Markdown

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
Copy Markdown
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
Copy Markdown

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
Copy Markdown
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