From 1d291cb7fdb0613165f12514fef2a6ca6c2b04b7 Mon Sep 17 00:00:00 2001 From: Wojciech Kwolek Date: Mon, 24 Aug 2020 03:53:29 +0200 Subject: [PATCH 1/2] Allow changing the path to the language server. Some users might want to use a different Python language server binary than the one automatically downloaded by the extension. For example, on some distributions of Linux, the official binaries do not work, and a patched version is needed. It can be installed from the repositories, and this patch allows the user to force coc-python to use it. This is accomplished by adding a setting `python.languageServerPath`, which, if non-empty, is used as the language server binary path instead of the one downloaded by the extension. --- package.json | 6 ++++++ src/activation/languageServer/languageClientFactory.ts | 6 +++++- src/common/configSettings.ts | 3 +++ src/common/types.ts | 1 + 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 4c2108d..ce49466 100644 --- a/package.json +++ b/package.json @@ -181,6 +181,12 @@ "description": "Automatically update the language server.", "scope": "application" }, + "python.languageServerPath": { + "type": "string", + "description": "Overrides the auto-installed Python Language server binary path.", + "default": "", + "scope": "resource" + }, "python.disableInstallationCheck": { "type": "boolean", "default": false, diff --git a/src/activation/languageServer/languageClientFactory.ts b/src/activation/languageServer/languageClientFactory.ts index e561aaf..5faf5a1 100644 --- a/src/activation/languageServer/languageClientFactory.ts +++ b/src/activation/languageServer/languageClientFactory.ts @@ -49,12 +49,16 @@ export class BaseLanguageClientFactory implements ILanguageClientFactory { @injectable() export class DownloadedLanguageClientFactory implements ILanguageClientFactory { constructor(@inject(IPlatformData) private readonly platformData: IPlatformData, + @inject(IConfigurationService) private readonly configurationService: IConfigurationService, @inject(ILanguageServerFolderService) private readonly languageServerFolderService: ILanguageServerFolderService, @inject(IExtensionContext) private readonly context: IExtensionContext) { } public async createLanguageClient(_resource: Resource, clientOptions: LanguageClientOptions, env?: NodeJS.ProcessEnv): Promise { + let serverModule = this.configurationService.getSettings().languageServerPath; const languageServerFolder = await this.languageServerFolderService.getLanguageServerFolderName() - const serverModule = path.join(this.context.storagePath, languageServerFolder, this.platformData.engineExecutableName) + if(serverModule === "") { + serverModule = path.join(this.context.storagePath, languageServerFolder, this.platformData.engineExecutableName) + } const serverOptions: Executable = { command: serverModule, args: [], diff --git a/src/common/configSettings.ts b/src/common/configSettings.ts index 0cffa24..af1ce14 100644 --- a/src/common/configSettings.ts +++ b/src/common/configSettings.ts @@ -42,6 +42,7 @@ export class PythonSettings implements IPythonSettings { public globalModuleInstallation = false public analysis!: IAnalysisSettings public autoUpdateLanguageServer = true + public languageServerPath = "" public datascience!: IDataScienceSettings protected readonly changed = new Emitter() @@ -147,6 +148,8 @@ export class PythonSettings implements IPythonSettings { this.downloadLanguageServer = systemVariables.resolveAny(pythonSettings.get('downloadLanguageServer', true))! this.jediEnabled = systemVariables.resolveAny(pythonSettings.get('jediEnabled', true))! this.autoUpdateLanguageServer = systemVariables.resolveAny(pythonSettings.get('autoUpdateLanguageServer', true))! + this.languageServerPath = systemVariables.resolveAny(pythonSettings.get('languageServerPath', ''))! + if (this.jediEnabled) { // tslint:disable-next-line:no-backbone-get-set-outside-model no-non-null-assertion this.jediPath = systemVariables.resolveAny(pythonSettings.get('jediPath'))! diff --git a/src/common/types.ts b/src/common/types.ts index cf9e95c..69b7338 100644 --- a/src/common/types.ts +++ b/src/common/types.ts @@ -163,6 +163,7 @@ export interface IPythonSettings { readonly globalModuleInstallation: boolean readonly analysis: IAnalysisSettings readonly autoUpdateLanguageServer: boolean + readonly languageServerPath: string readonly datascience: IDataScienceSettings readonly onDidChange: Event } From 2a5d03e6af462efd5d7ef3df33ef323a62c6a981 Mon Sep 17 00:00:00 2001 From: Wojciech Kwolek Date: Mon, 24 Aug 2020 03:59:11 +0200 Subject: [PATCH 2/2] Add python.languageServerPath to the readme --- Readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Readme.md b/Readme.md index f0f3036..2fdac2d 100644 --- a/Readme.md +++ b/Readme.md @@ -80,6 +80,7 @@ Except from `test`, `debug` and `datascience` features of [vscode-python](https: - `python.autoComplete.showAdvancedMembers`:Controls appearance of methods with double underscores in the completion list., default: `true` - `python.autoComplete.typeshedPaths`:Specifies paths to local typeshed repository clone(s) for the Python language server., default: `[]` - `python.autoUpdateLanguageServer`:Automatically update the language server., default: `true` +- `python.languageServerPath`:If not empty, use the provided language server binary instead of the one that's been downloaded., default: `""` - `python.disableInstallationCheck`:Whether to check if Python is installed (also warn when using the macOS-installed Python)., default: `false` - `python.envFile`:Absolute path to a file containing environment variable definitions., default: `"${workspaceFolder}/.env"` - `python.trace.server`:Trace level of tsserver, default: `"off"`