-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add "Default" LS setting, which picks between Jedi/Pylance #16139
Conversation
"Jedi", | ||
"JediLSP", | ||
"Pylance", | ||
"Microsoft", | ||
"None" | ||
], | ||
"default": "Jedi", | ||
"default": "Default", |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -1225,13 +1225,14 @@ | |||
"python.languageServer": { | |||
"type": "string", | |||
"enum": [ | |||
"Default", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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.
"Jedi", | ||
"JediLSP", | ||
"Pylance", | ||
"Microsoft", | ||
"None" | ||
], | ||
"default": "Jedi", | ||
"default": "Default", |
There was a problem hiding this comment.
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?
Added @karthiknadig because he did the JediLSP work |
…new-default-ls-setting
We'll probably want to change vscode-python/src/client/activation/activationService.ts Lines 236 to 241 in fb6b722
Is Python 2 going away anytime soon? :) |
Fixed the title; no idea why it did that. |
What happened |
GH really did not like that. I'll have to rebase and resend. |
There was a problem hiding this 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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need not be exported.
There was a problem hiding this comment.
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
.
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.