From 964a99c5de566ba151f3e9c325a5ff808a5fca3c Mon Sep 17 00:00:00 2001 From: Mikhail Arkhipov Date: Fri, 8 Jun 2018 11:09:08 -0700 Subject: [PATCH] Add command for loading of LS extensions (#1914) * Undo changes * Test fixes * Increase timeout * Remove double event listening * Remove test * Revert "Remove test" This reverts commit e240c3fd117c38b9e6fdcbdd1ba2715789fefe48. * Revert "Remove double event listening" This reverts commit af573be27372a79d5589e2134002cc753bb54f2a. * #1096 The if statement is automatically formatted incorrectly * Merge fix * Add more tests * More tests * Typo * Test * Also better handle multiline arguments * Add a couple missing periods [skip ci] * Undo changes * Test fixes * Increase timeout * Remove double event listening * Remove test * Revert "Remove test" This reverts commit e240c3fd117c38b9e6fdcbdd1ba2715789fefe48. * Revert "Remove double event listening" This reverts commit af573be27372a79d5589e2134002cc753bb54f2a. * Merge fix * #1257 On type formatting errors for args and kwargs * Handle f-strings * Stop importing from test code * #1308 Single line statements leading to an indentation on the next line * #726 editing python after inline if statement invalid indent * Undo change * Move constant * Harden LS startup error checks * #1364 Intellisense doesn't work after specific const string * Telemetry for the analysis enging * PR feedback * Fix typo * Test baseline update * Improve function argument detection * Specify markdown * Remove Pythia * Load extension command --- src/client/activation/analysis.ts | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/client/activation/analysis.ts b/src/client/activation/analysis.ts index 522722b39a69..7957bdc55172 100644 --- a/src/client/activation/analysis.ts +++ b/src/client/activation/analysis.ts @@ -5,8 +5,9 @@ import { inject, injectable } from 'inversify'; import * as path from 'path'; import { ExtensionContext, OutputChannel } from 'vscode'; import { Disposable, LanguageClient, LanguageClientOptions, ServerOptions } from 'vscode-languageclient'; -import { IApplicationShell } from '../common/application/types'; +import { IApplicationShell, ICommandManager } from '../common/application/types'; import { isTestExecution, STANDARD_OUTPUT_CHANNEL } from '../common/constants'; +import { createDeferred, Deferred } from '../common/helpers'; import { IFileSystem, IPlatformService } from '../common/platform/types'; import { StopWatch } from '../common/stopWatch'; import { IConfigurationService, IExtensionContext, IOutputChannel } from '../common/types'; @@ -28,6 +29,7 @@ const PYTHON = 'python'; const dotNetCommand = 'dotnet'; const languageClientName = 'Python Tools'; const analysisEngineFolder = 'analysis'; +const loadExtensionCommand = 'python._loadLanguageServerExtension'; @injectable() export class AnalysisExtensionActivator implements IExtensionActivator { @@ -38,7 +40,9 @@ export class AnalysisExtensionActivator implements IExtensionActivator { private readonly sw = new StopWatch(); private readonly platformData: PlatformData; private readonly interpreterService: IInterpreterService; + private readonly startupCompleted: Deferred; private readonly disposables: Disposable[] = []; + private languageClient: LanguageClient | undefined; private readonly context: ExtensionContext; private interpreterHash: string = ''; @@ -51,6 +55,17 @@ export class AnalysisExtensionActivator implements IExtensionActivator { this.fs = this.services.get(IFileSystem); this.platformData = new PlatformData(services.get(IPlatformService), this.fs); this.interpreterService = this.services.get(IInterpreterService); + + this.startupCompleted = createDeferred(); + const commandManager = this.services.get(ICommandManager); + this.disposables.push(commandManager.registerCommand(loadExtensionCommand, + async (args) => { + if (this.languageClient) { + await this.startupCompleted.promise; + this.languageClient.sendRequest('python/loadExtension', args); + } + } + )); } public async activate(): Promise { @@ -119,9 +134,15 @@ export class AnalysisExtensionActivator implements IExtensionActivator { } private async startLanguageClient(context: ExtensionContext): Promise { + this.languageClient!.onReady() + .then(() => { + this.startupCompleted.resolve(); + }) + .catch(error => this.startupCompleted.reject(error)); + context.subscriptions.push(this.languageClient!.start()); if (isTestExecution()) { - await this.languageClient!.onReady(); + await this.startupCompleted.promise; } }