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

Put Jedi behind LSP #15308

Merged
merged 13 commits into from
Feb 5, 2021
6 changes: 0 additions & 6 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ src/client/providers/referenceProvider.ts
src/client/providers/terminalProvider.ts
src/client/providers/signatureProvider.ts

src/client/activation/serviceRegistry.ts
src/client/activation/languageServer/manager.ts
src/client/activation/languageServer/languageServerExtension.ts
src/client/activation/languageServer/languageServerProxy.ts
Expand All @@ -406,7 +405,6 @@ src/client/activation/commands.ts
src/client/activation/activationManager.ts
src/client/activation/progress.ts
src/client/activation/extensionSurvey.ts
src/client/activation/types.ts
src/client/activation/common/languageServerChangeHandler.ts
src/client/activation/common/activatorBase.ts
src/client/activation/common/languageServerFolderService.ts
Expand All @@ -417,7 +415,6 @@ src/client/activation/common/downloadChannelRules.ts
src/client/activation/refCountedLanguageServer.ts
src/client/activation/jedi.ts
src/client/activation/languageClientMiddleware.ts
src/client/activation/activationService.ts
src/client/activation/node/manager.ts
src/client/activation/node/cancellationUtils.ts
src/client/activation/node/languageServerProxy.ts
Expand Down Expand Up @@ -512,7 +509,6 @@ src/client/testing/display/main.ts
src/client/testing/display/picker.ts
src/client/testing/configuration.ts

src/client/common/configuration/service.ts
src/client/common/serviceRegistry.ts
src/client/common/helpers.ts
src/client/common/net/browser.ts
Expand Down Expand Up @@ -560,7 +556,6 @@ src/client/common/terminal/environmentActivationProviders/bash.ts
src/client/common/terminal/environmentActivationProviders/pyenvActivationProvider.ts
src/client/common/utils/decorators.ts
src/client/common/utils/enum.ts
src/client/common/utils/localize.ts
src/client/common/utils/platform.ts
src/client/common/utils/stopWatch.ts
src/client/common/utils/random.ts
Expand All @@ -578,7 +573,6 @@ src/client/common/dotnet/services/unknownOsCompatibilityService.ts
src/client/common/dotnet/services/macCompatibilityService.ts
src/client/common/dotnet/services/linuxCompatibilityService.ts
src/client/common/dotnet/services/windowsCompatibilityService.ts
src/client/common/types.ts
src/client/common/logger.ts
src/client/common/constants.ts
src/client/common/variables/serviceRegistry.ts
Expand Down
1 change: 1 addition & 0 deletions news/1 Enhancements/11995.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use Language Server Protocol to work with Jedi.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,7 @@
"pythonSendEntireLineToREPL",
"pythonTensorboardExperiment",
"pythonDiscoveryModule",
"pythonJediLSP",
"All"
]
},
Expand Down Expand Up @@ -1078,6 +1079,7 @@
"pythonSendEntireLineToREPL",
"pythonTensorboardExperiment",
"pythonDiscoveryModule",
"pythonJediLSP",
"All"
]
},
Expand Down Expand Up @@ -1168,13 +1170,14 @@
"python.jediPath": {
"type": "string",
"default": "",
"description": "Path to directory containing the Jedi library (this path will contain the 'Jedi' sub directory). Note: since Jedi depends on Parso, if using this setting you will need to ensure a suitable version of Parso is available.",
"description": "Path to directory containing the Jedi library (this path will contain the 'Jedi' sub directory). Note: since Jedi depends on Parso, if using this setting you will need to ensure a suitable version of Parso is available. This setting only works with \"languageServer=Jedi\" and not JediLSP.",
"scope": "resource"
},
"python.languageServer": {
"type": "string",
"enum": [
"Jedi",
"JediLSP",
"Pylance",
"Microsoft",
"None"
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
"LanguageService.startingJedi": "Starting Jedi Python language engine.",
"LanguageService.startingMicrosoft": "Starting Microsoft Python language server.",
"LanguageService.startingPylance": "Starting Pylance language server.",
"LanguageService.startingJediLSP": "Starting Jedi language server.",
"LanguageService.startingNone": "Editor support is inactive since language server is set to None.",
"LanguageService.reloadAfterLanguageServerChange": "Please reload the window switching between language servers.",
"AttachProcess.unsupportedOS": "Operating system '{0}' not supported.",
Expand Down
2 changes: 0 additions & 2 deletions pythonFiles/runJediLanguageServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@

from jedi_language_server.cli import cli

# Trick language server into thinking it started from 'jedi-language-server.exe'
sys.argv[0] = "jedi-language-server.exe"
sys.exit(cli())
17 changes: 13 additions & 4 deletions src/client/activation/activationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,17 @@ interface IActivatedServer {
export class LanguageServerExtensionActivationService
implements IExtensionActivationService, ILanguageServerCache, Disposable {
private cache = new Map<string, Promise<RefCountedLanguageServer>>();

private activatedServer?: IActivatedServer;

private readonly workspaceService: IWorkspaceService;

private readonly output: OutputChannel;

private readonly interpreterService: IInterpreterService;

private readonly languageServerChangeHandler: LanguageServerChangeHandler;

private resource!: Resource;

constructor(
Expand Down Expand Up @@ -138,7 +144,7 @@ export class LanguageServerExtensionActivationService
return result;
}

public dispose() {
public dispose(): void {
if (this.activatedServer) {
this.activatedServer.server.dispose();
}
Expand Down Expand Up @@ -185,8 +191,8 @@ export class LanguageServerExtensionActivationService
);
}

protected async onWorkspaceFoldersChanged() {
//If an activated workspace folder was removed, dispose its activator
protected async onWorkspaceFoldersChanged(): Promise<void> {
// If an activated workspace folder was removed, dispose its activator
const workspaceKeys = await Promise.all(
this.workspaceService.workspaceFolders!.map((workspaceFolder) => this.getKey(workspaceFolder.uri)),
);
Expand Down Expand Up @@ -263,6 +269,9 @@ export class LanguageServerExtensionActivationService
case LanguageServerType.Jedi:
outputLine = LanguageService.startingJedi();
break;
case LanguageServerType.JediLSP:
outputLine = LanguageService.startingJediLSP();
break;
case LanguageServerType.Microsoft:
outputLine = LanguageService.startingMicrosoft();
break;
Expand Down Expand Up @@ -304,7 +313,7 @@ export class LanguageServerExtensionActivationService
resource,
workspacePathNameForGlobalWorkspaces,
);
interpreter = interpreter ? interpreter : await this.interpreterService.getActiveInterpreter(resource);
interpreter = interpreter || (await this.interpreterService.getActiveInterpreter(resource));
const interperterPortion = interpreter ? `${interpreter.path}-${interpreter.envName}` : '';
return `${resourcePortion}-${interperterPortion}`;
}
Expand Down
18 changes: 18 additions & 0 deletions src/client/activation/jedi/analysisOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { IEnvironmentVariablesProvider } from '../../common/variables/types';
import { LanguageServerAnalysisOptionsWithEnv } from '../common/analysisOptions';
import { ILanguageServerOutputChannel } from '../types';

/* eslint-disable @typescript-eslint/explicit-module-boundary-types, class-methods-use-this */

@injectable()
export class JediLanguageServerAnalysisOptions extends LanguageServerAnalysisOptionsWithEnv {
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
Expand All @@ -15,4 +17,20 @@ export class JediLanguageServerAnalysisOptions extends LanguageServerAnalysisOpt
) {
super(envVarsProvider, lsOutputChannel);
}

protected async getInitializationOptions() {
return {
markupKindPreferred: 'markdown',
completion: {
resolveEagerly: false,
disableSnippets: false,
karthiknadig marked this conversation as resolved.
Show resolved Hide resolved
},
diagnostics: {
enable: true,
didOpen: true,
didSave: true,
didChange: true,
},
};
}
}
8 changes: 3 additions & 5 deletions src/client/activation/jedi/languageClientFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ export class JediLanguageClientFactory implements ILanguageClientFactory {
clientOptions: LanguageClientOptions,
): Promise<LanguageClient> {
// Just run the language server using a module
const jediServerModulePath = path.join(EXTENSION_ROOT_DIR, 'pythonFiles', 'runJediLanguageServer.py');
const lsScriptPath = path.join(EXTENSION_ROOT_DIR, 'pythonFiles', 'runJediLanguageServer.py');
const interpreter = await this.interpreterService.getActiveInterpreter(resource);
const pythonPath = interpreter ? interpreter.path : 'python';
const args = [jediServerModulePath];
const serverOptions: ServerOptions = {
command: pythonPath,
args,
command: interpreter ? interpreter.path : 'python',
args: [lsScriptPath],
};

// eslint-disable-next-line global-require
Expand Down
4 changes: 2 additions & 2 deletions src/client/activation/jedi/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class JediLanguageServerManager implements ILanguageServerManager {
constructor(
@inject(IServiceContainer) private readonly serviceContainer: IServiceContainer,
@inject(ILanguageServerAnalysisOptions)
@named(LanguageServerType.Jedi)
@named(LanguageServerType.JediLSP)
private readonly analysisOptions: ILanguageServerAnalysisOptions,
@inject(ICommandManager) commandManager: ICommandManager,
) {
Expand Down Expand Up @@ -134,7 +134,7 @@ export class JediLanguageServerManager implements ILanguageServerManager {
const options = await this.analysisOptions.getAnalysisOptions();
this.middleware = new LanguageClientMiddleware(
this.serviceContainer,
LanguageServerType.Jedi,
LanguageServerType.JediLSP,
() => this.languageServerProxy?.languageClient,
this.lsVersion,
);
Expand Down
Loading