Skip to content

Commit 964a99c

Browse files
author
Mikhail Arkhipov
authored
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 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
1 parent 8009805 commit 964a99c

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/client/activation/analysis.ts

+23-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import { inject, injectable } from 'inversify';
55
import * as path from 'path';
66
import { ExtensionContext, OutputChannel } from 'vscode';
77
import { Disposable, LanguageClient, LanguageClientOptions, ServerOptions } from 'vscode-languageclient';
8-
import { IApplicationShell } from '../common/application/types';
8+
import { IApplicationShell, ICommandManager } from '../common/application/types';
99
import { isTestExecution, STANDARD_OUTPUT_CHANNEL } from '../common/constants';
10+
import { createDeferred, Deferred } from '../common/helpers';
1011
import { IFileSystem, IPlatformService } from '../common/platform/types';
1112
import { StopWatch } from '../common/stopWatch';
1213
import { IConfigurationService, IExtensionContext, IOutputChannel } from '../common/types';
@@ -28,6 +29,7 @@ const PYTHON = 'python';
2829
const dotNetCommand = 'dotnet';
2930
const languageClientName = 'Python Tools';
3031
const analysisEngineFolder = 'analysis';
32+
const loadExtensionCommand = 'python._loadLanguageServerExtension';
3133

3234
@injectable()
3335
export class AnalysisExtensionActivator implements IExtensionActivator {
@@ -38,7 +40,9 @@ export class AnalysisExtensionActivator implements IExtensionActivator {
3840
private readonly sw = new StopWatch();
3941
private readonly platformData: PlatformData;
4042
private readonly interpreterService: IInterpreterService;
43+
private readonly startupCompleted: Deferred<void>;
4144
private readonly disposables: Disposable[] = [];
45+
4246
private languageClient: LanguageClient | undefined;
4347
private readonly context: ExtensionContext;
4448
private interpreterHash: string = '';
@@ -51,6 +55,17 @@ export class AnalysisExtensionActivator implements IExtensionActivator {
5155
this.fs = this.services.get<IFileSystem>(IFileSystem);
5256
this.platformData = new PlatformData(services.get<IPlatformService>(IPlatformService), this.fs);
5357
this.interpreterService = this.services.get<IInterpreterService>(IInterpreterService);
58+
59+
this.startupCompleted = createDeferred<void>();
60+
const commandManager = this.services.get<ICommandManager>(ICommandManager);
61+
this.disposables.push(commandManager.registerCommand(loadExtensionCommand,
62+
async (args) => {
63+
if (this.languageClient) {
64+
await this.startupCompleted.promise;
65+
this.languageClient.sendRequest('python/loadExtension', args);
66+
}
67+
}
68+
));
5469
}
5570

5671
public async activate(): Promise<boolean> {
@@ -119,9 +134,15 @@ export class AnalysisExtensionActivator implements IExtensionActivator {
119134
}
120135

121136
private async startLanguageClient(context: ExtensionContext): Promise<void> {
137+
this.languageClient!.onReady()
138+
.then(() => {
139+
this.startupCompleted.resolve();
140+
})
141+
.catch(error => this.startupCompleted.reject(error));
142+
122143
context.subscriptions.push(this.languageClient!.start());
123144
if (isTestExecution()) {
124-
await this.languageClient!.onReady();
145+
await this.startupCompleted.promise;
125146
}
126147
}
127148

0 commit comments

Comments
 (0)