Skip to content

Commit

Permalink
Add command for loading of LS extensions (#1914)
Browse files Browse the repository at this point in the history
* Undo changes

* Test fixes

* Increase timeout

* Remove double event listening

* Remove test

* Revert "Remove test"

This reverts commit e240c3f.

* Revert "Remove double event listening"

This reverts commit af573be.

* #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 e240c3f.

* Revert "Remove double event listening"

This reverts commit af573be.

* 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
  • Loading branch information
Mikhail Arkhipov authored Jun 8, 2018
1 parent 8009805 commit 964a99c
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/client/activation/analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 {
Expand All @@ -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<void>;
private readonly disposables: Disposable[] = [];

private languageClient: LanguageClient | undefined;
private readonly context: ExtensionContext;
private interpreterHash: string = '';
Expand All @@ -51,6 +55,17 @@ export class AnalysisExtensionActivator implements IExtensionActivator {
this.fs = this.services.get<IFileSystem>(IFileSystem);
this.platformData = new PlatformData(services.get<IPlatformService>(IPlatformService), this.fs);
this.interpreterService = this.services.get<IInterpreterService>(IInterpreterService);

this.startupCompleted = createDeferred<void>();
const commandManager = this.services.get<ICommandManager>(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<boolean> {
Expand Down Expand Up @@ -119,9 +134,15 @@ export class AnalysisExtensionActivator implements IExtensionActivator {
}

private async startLanguageClient(context: ExtensionContext): Promise<void> {
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;
}
}

Expand Down

0 comments on commit 964a99c

Please sign in to comment.