From fd4935de600f65bc179df1f729fdfe3853d43f4b Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Mon, 3 Apr 2017 18:48:36 -0700 Subject: [PATCH] Handle typesInstallerInitializationFailed events (#23876) * Handle typesInstallerInitializationFailed Display a warning message when the ts typings installer fails to initilize. One possible cause is that npm is not installed * Fix a spell --- extensions/typescript/src/typescriptService.ts | 1 + extensions/typescript/src/typescriptServiceClient.ts | 10 ++++++++++ extensions/typescript/src/utils/typingsStatus.ts | 8 ++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/extensions/typescript/src/typescriptService.ts b/extensions/typescript/src/typescriptService.ts index 289c227daf3..5edfa590f2a 100644 --- a/extensions/typescript/src/typescriptService.ts +++ b/extensions/typescript/src/typescriptService.ts @@ -74,6 +74,7 @@ export interface ITypescriptServiceClient { onProjectLanguageServiceStateChanged: Event; onDidBeginInstallTypings: Event; onDidEndInstallTypings: Event; + onTypesInstallerInitializationFailed: Event; logTelemetry(eventName: string, properties?: { [prop: string]: string }): void; diff --git a/extensions/typescript/src/typescriptServiceClient.ts b/extensions/typescript/src/typescriptServiceClient.ts index 7c1bb4385d1..fef0d1cdf48 100644 --- a/extensions/typescript/src/typescriptServiceClient.ts +++ b/extensions/typescript/src/typescriptServiceClient.ts @@ -160,6 +160,7 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient private _onProjectLanguageServiceStateChanged = new EventEmitter(); private _onDidBeginInstallTypings = new EventEmitter(); private _onDidEndInstallTypings = new EventEmitter(); + private _onTypesInstallerInitializationFailed = new EventEmitter(); private _packageInfo: IPackageInfo | null; private _apiVersion: API; @@ -265,6 +266,10 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient return this._onDidEndInstallTypings.event; } + get onTypesInstallerInitializationFailed(): Event { + return this._onTypesInstallerInitializationFailed.event; + } + private get output(): OutputChannel { if (!this._output) { this._output = window.createOutputChannel(localize('channelName', 'TypeScript')); @@ -1017,6 +1022,11 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient if (data) { this._onDidEndInstallTypings.fire(data); } + } else if (event.event === 'typesInstallerInitializationFailed') { + const data = (event as Proto.TypesInstallerInitializationFailedEvent).body; + if (data) { + this._onTypesInstallerInitializationFailed.fire(data); + } } } else { throw new Error('Unknown message type ' + message.type + ' recevied'); diff --git a/extensions/typescript/src/utils/typingsStatus.ts b/extensions/typescript/src/utils/typingsStatus.ts index de5cd9d291e..6e7a98751fe 100644 --- a/extensions/typescript/src/utils/typingsStatus.ts +++ b/extensions/typescript/src/utils/typingsStatus.ts @@ -68,8 +68,8 @@ export class AtaProgressReporter { constructor(client: ITypescriptServiceClient) { this._disposable = vscode.Disposable.from( client.onDidBeginInstallTypings(e => this._onBegin(e.eventId)), - client.onDidEndInstallTypings(e => this._onEndOrTimeout(e.eventId)) - ); + client.onDidEndInstallTypings(e => this._onEndOrTimeout(e.eventId)), + client.onTypesInstallerInitializationFailed(_ => this.onTypesInstallerInitializationFailed())); } dispose(): void { @@ -96,4 +96,8 @@ export class AtaProgressReporter { resolve(); } } + + private onTypesInstallerInitializationFailed() { + vscode.window.showWarningMessage(localize('typesInstallerInitializationFailed', "Could not install typings files for JS/TS language features. Please ensure that NPM is installed")); + } } -- GitLab