forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add "Default" LS setting, which picks between Jedi/Pylance #16155
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
Merged
Jake Bailey (jakebailey)
merged 8 commits into
microsoft:main
from
jakebailey:new-default-ls-setting
May 5, 2021
+193
−155
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9ff3a4c
Add Default LS setting
jakebailey 3c4829b
Remove unused code
jakebailey d0e65ee
Remove debug log
jakebailey 4045a5c
Restore tryGet
jakebailey 1e403cb
PR feedback
jakebailey 50b928d
Handle Python 2.7 fallback case
jakebailey ebd981b
Add news entry
jakebailey e0586f5
Fix typo
jakebailey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add a "Default" language server option, which dynamically chooses which language server to use. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -240,6 +240,13 @@ export class LanguageServerExtensionActivationService | |
| } | ||
| } | ||
|
|
||
| if (serverType === LanguageServerType.Node && interpreter && interpreter.version) { | ||
| if (interpreter.version.major < 3) { | ||
| sendTelemetryEvent(EventName.JEDI_FALLBACK); | ||
| serverType = LanguageServerType.Jedi; | ||
| } | ||
| } | ||
|
|
||
| this.sendTelemetryForChosenLanguageServer(serverType).ignoreErrors(); | ||
|
|
||
| await this.logStartup(serverType); | ||
|
|
@@ -310,7 +317,7 @@ export class LanguageServerExtensionActivationService | |
| const configurationService = this.serviceContainer.get<IConfigurationService>(IConfigurationService); | ||
| const serverType = configurationService.getSettings(this.resource).languageServer; | ||
| if (serverType === LanguageServerType.Node) { | ||
| return 'shared-ls'; | ||
| return LanguageServerType.Node; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The key is compared against the server type in some conditions (bad!), but this will at least make things not break in those cases. |
||
| } | ||
|
|
||
| const resourcePortion = this.workspaceService.getWorkspaceFolderIdentifier( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import { injectable } from 'inversify'; | ||
| import { PYLANCE_EXTENSION_ID } from '../../common/constants'; | ||
| import { JediLSP } from '../../common/experiments/groups'; | ||
| import { IDefaultLanguageServer, IExperimentService, IExtensions, DefaultLSType } from '../../common/types'; | ||
| import { IServiceManager } from '../../ioc/types'; | ||
| import { ILSExtensionApi } from '../node/languageServerFolderService'; | ||
| import { LanguageServerType } from '../types'; | ||
|
|
||
| @injectable() | ||
| class DefaultLanguageServer implements IDefaultLanguageServer { | ||
| public readonly defaultLSType: DefaultLSType; | ||
|
|
||
| constructor(defaultServer: DefaultLSType) { | ||
| this.defaultLSType = defaultServer; | ||
| } | ||
| } | ||
|
|
||
| export async function setDefaultLanguageServer( | ||
| experimentService: IExperimentService, | ||
| extensions: IExtensions, | ||
| serviceManager: IServiceManager, | ||
| ): Promise<void> { | ||
| const lsType = await getDefaultLanguageServer(experimentService, extensions); | ||
| serviceManager.addSingletonInstance<IDefaultLanguageServer>( | ||
| IDefaultLanguageServer, | ||
| new DefaultLanguageServer(lsType), | ||
| ); | ||
| } | ||
|
|
||
| async function getDefaultLanguageServer( | ||
| experimentService: IExperimentService, | ||
| extensions: IExtensions, | ||
| ): Promise<DefaultLSType> { | ||
| if (extensions.getExtension<ILSExtensionApi>(PYLANCE_EXTENSION_ID)) { | ||
| return LanguageServerType.Node; | ||
| } | ||
|
|
||
| return (await experimentService.inExperiment(JediLSP.experiment)) | ||
| ? LanguageServerType.JediLSP | ||
| : LanguageServerType.Jedi; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| 'use strict'; | ||
|
|
||
| import { expect } from 'chai'; | ||
| import { anything, instance, mock, when, verify } from 'ts-mockito'; | ||
| import { Extension } from 'vscode'; | ||
| import { setDefaultLanguageServer } from '../../client/activation/common/defaultlanguageServer'; | ||
| import { LanguageServerType } from '../../client/activation/types'; | ||
| import { PYLANCE_EXTENSION_ID } from '../../client/common/constants'; | ||
| import { JediLSP } from '../../client/common/experiments/groups'; | ||
| import { ExperimentService } from '../../client/common/experiments/service'; | ||
| import { IDefaultLanguageServer, IExperimentService, IExtensions } from '../../client/common/types'; | ||
| import { ServiceManager } from '../../client/ioc/serviceManager'; | ||
| import { IServiceManager } from '../../client/ioc/types'; | ||
|
|
||
| suite('Activation - setDefaultLanguageServer()', () => { | ||
| let experimentService: IExperimentService; | ||
| let extensions: IExtensions; | ||
| let extension: Extension<unknown>; | ||
| let serviceManager: IServiceManager; | ||
| setup(() => { | ||
| experimentService = mock(ExperimentService); | ||
| extensions = mock(); | ||
| extension = mock(); | ||
| serviceManager = mock(ServiceManager); | ||
| }); | ||
|
|
||
| test('Pylance not installed and NOT in experiment', async () => { | ||
| let defaultServerType; | ||
|
|
||
| when(extensions.getExtension(PYLANCE_EXTENSION_ID)).thenReturn(undefined); | ||
| when(experimentService.inExperiment(JediLSP.experiment)).thenResolve(false); | ||
| when(serviceManager.addSingletonInstance<IDefaultLanguageServer>(IDefaultLanguageServer, anything())).thenCall( | ||
| (_symbol, value: IDefaultLanguageServer) => { | ||
| defaultServerType = value.defaultLSType; | ||
| }, | ||
| ); | ||
|
|
||
| await setDefaultLanguageServer(instance(experimentService), instance(extensions), instance(serviceManager)); | ||
|
|
||
| verify(extensions.getExtension(PYLANCE_EXTENSION_ID)).once(); | ||
| verify(experimentService.inExperiment(JediLSP.experiment)).once(); | ||
| verify(serviceManager.addSingletonInstance<IDefaultLanguageServer>(IDefaultLanguageServer, anything())).once(); | ||
| expect(defaultServerType).to.equal(LanguageServerType.Jedi); | ||
| }); | ||
|
|
||
| test('Pylance not installed and in experiment', async () => { | ||
| let defaultServerType; | ||
| when(extensions.getExtension(PYLANCE_EXTENSION_ID)).thenReturn(undefined); | ||
| when(experimentService.inExperiment(JediLSP.experiment)).thenResolve(true); | ||
| when(serviceManager.addSingletonInstance<IDefaultLanguageServer>(IDefaultLanguageServer, anything())).thenCall( | ||
| (_symbol, value: IDefaultLanguageServer) => { | ||
| defaultServerType = value.defaultLSType; | ||
| }, | ||
| ); | ||
|
|
||
| await setDefaultLanguageServer(instance(experimentService), instance(extensions), instance(serviceManager)); | ||
|
|
||
| verify(extensions.getExtension(PYLANCE_EXTENSION_ID)).once(); | ||
| verify(experimentService.inExperiment(JediLSP.experiment)).once(); | ||
| verify(serviceManager.addSingletonInstance<IDefaultLanguageServer>(IDefaultLanguageServer, anything())).once(); | ||
| expect(defaultServerType).to.equal(LanguageServerType.JediLSP); | ||
| }); | ||
|
|
||
| test('Pylance installed and NOT in experiment', async () => { | ||
| let defaultServerType; | ||
|
|
||
| when(extensions.getExtension(PYLANCE_EXTENSION_ID)).thenReturn(instance(extension)); | ||
| when(experimentService.inExperiment(JediLSP.experiment)).thenResolve(false); | ||
| when(serviceManager.addSingletonInstance<IDefaultLanguageServer>(IDefaultLanguageServer, anything())).thenCall( | ||
| (_symbol, value: IDefaultLanguageServer) => { | ||
| defaultServerType = value.defaultLSType; | ||
| }, | ||
| ); | ||
|
|
||
| await setDefaultLanguageServer(instance(experimentService), instance(extensions), instance(serviceManager)); | ||
|
|
||
| verify(extensions.getExtension(PYLANCE_EXTENSION_ID)).once(); | ||
| verify(experimentService.inExperiment(JediLSP.experiment)).never(); | ||
| verify(serviceManager.addSingletonInstance<IDefaultLanguageServer>(IDefaultLanguageServer, anything())).once(); | ||
| expect(defaultServerType).to.equal(LanguageServerType.Node); | ||
| }); | ||
|
|
||
| test('Pylance installed and in experiment', async () => { | ||
| let defaultServerType; | ||
| when(extensions.getExtension(PYLANCE_EXTENSION_ID)).thenReturn(instance(extension)); | ||
| when(experimentService.inExperiment(JediLSP.experiment)).thenResolve(true); | ||
| when(serviceManager.addSingletonInstance<IDefaultLanguageServer>(IDefaultLanguageServer, anything())).thenCall( | ||
| (_symbol, value: IDefaultLanguageServer) => { | ||
| defaultServerType = value.defaultLSType; | ||
| }, | ||
| ); | ||
|
|
||
| await setDefaultLanguageServer(instance(experimentService), instance(extensions), instance(serviceManager)); | ||
|
|
||
| verify(extensions.getExtension(PYLANCE_EXTENSION_ID)).once(); | ||
| verify(experimentService.inExperiment(JediLSP.experiment)).never(); | ||
| verify(serviceManager.addSingletonInstance<IDefaultLanguageServer>(IDefaultLanguageServer, anything())).once(); | ||
| expect(defaultServerType).to.equal(LanguageServerType.Node); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.