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

Provide LS analysis progress display in the status bar #2099

Merged
merged 9 commits into from
Jul 10, 2018
1 change: 1 addition & 0 deletions news/1 Enhancements/1591.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Language server now reports code analysis progress in the status bar.
32 changes: 19 additions & 13 deletions src/client/activation/analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { getTelemetryReporter } from '../telemetry/telemetry';
import { AnalysisEngineDownloader } from './downloader';
import { InterpreterData, InterpreterDataService } from './interpreterDataService';
import { PlatformData } from './platformData';
import { ProgressReporting } from './progress';
import { IExtensionActivator } from './types';

const PYTHON = 'python';
Expand Down Expand Up @@ -49,6 +50,8 @@ export class AnalysisExtensionActivator implements IExtensionActivator {
private excludedFiles: string[] = [];
private typeshedPaths: string[] = [];
private loadExtensionArgs: {} | undefined;
// tslint:disable-next-line:no-unused-variable
private progressReporting: ProgressReporting | undefined;

constructor(@inject(IServiceContainer) private readonly services: IServiceContainer) {
this.context = this.services.get<IExtensionContext>(IExtensionContext);
Expand Down Expand Up @@ -134,20 +137,19 @@ export class AnalysisExtensionActivator implements IExtensionActivator {
}

private async startLanguageClient(): Promise<void> {
this.languageClient!.onReady()
.then(() => {
this.startupCompleted.resolve();
if (this.loadExtensionArgs) {
this.languageClient!.sendRequest('python/loadExtension', this.loadExtensionArgs);
this.loadExtensionArgs = undefined;
}
})
.catch(error => this.startupCompleted.reject(error));

this.context.subscriptions.push(this.languageClient!.start());
if (isTestExecution()) {
await this.startupCompleted.promise;
await this.serverReady();
this.progressReporting = new ProgressReporting(this.languageClient!);
}

private async serverReady(): Promise<void> {
while (!this.languageClient!.initializeResult) {
await new Promise(resolve => setTimeout(resolve, 100));
}
if (this.loadExtensionArgs) {
this.languageClient!.sendRequest('python/loadExtension', this.loadExtensionArgs);
}
this.startupCompleted.resolve();
}

private createSimpleLanguageClient(clientOptions: LanguageClientOptions): LanguageClient {
Expand Down Expand Up @@ -215,6 +217,8 @@ export class AnalysisExtensionActivator implements IExtensionActivator {
this.excludedFiles = this.getExcludedFiles();
this.typeshedPaths = this.getTypeshedPaths(settings);

const traceLogging = (settings.analysis && settings.analysis.traceLogging) ? settings.analysis.traceLogging : false;

// Options to control the language client
return {
// Register the server for Python documents
Expand All @@ -237,7 +241,9 @@ export class AnalysisExtensionActivator implements IExtensionActivator {
searchPaths,
typeStubSearchPaths: this.typeshedPaths,
excludeFiles: this.excludedFiles,
testEnvironment: isTestExecution()
testEnvironment: isTestExecution(),
analysisUpdates: true,
traceLogging
}
};
}
Expand Down
46 changes: 46 additions & 0 deletions src/client/activation/progress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { Progress, ProgressLocation, window } from 'vscode';
import { Disposable, LanguageClient } from 'vscode-languageclient';
import { createDeferred, Deferred } from '../common/helpers';

export class ProgressReporting {
private statusBarMessage: Disposable | undefined;
private progress: Progress<{ message?: string; increment?: number }> | undefined;
private progressDeferred: Deferred<void> | undefined;

constructor(private readonly languageClient: LanguageClient) {
this.languageClient.onNotification('python/setStatusBarMessage', (m: string) => {
if (this.statusBarMessage) {
this.statusBarMessage.dispose();
}
this.statusBarMessage = window.setStatusBarMessage(m);
});

this.languageClient.onNotification('python/beginProgress', async _ => {
this.progressDeferred = createDeferred<void>();
window.withProgress({
location: ProgressLocation.Window,
title: ''
}, progress => {
this.progress = progress;
return this.progressDeferred!.promise;
});
});

this.languageClient.onNotification('python/reportProgress', (m: string) => {
if (!this.progress) {
return;
}
this.progress.report({ message: m });
});

this.languageClient.onNotification('python/endProgress', _ => {
if (this.progressDeferred) {
this.progressDeferred.resolve();
this.progressDeferred = undefined;
}
});
}
}
1 change: 1 addition & 0 deletions src/client/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ export interface IAnalysisSettings {
readonly warnings: string[];
readonly information: string[];
readonly disabled: string[];
readonly traceLogging: boolean;
}

export const IConfigurationService = Symbol('IConfigurationService');
Expand Down