From a3562fa1656f26ac39d02316ca150689e392f7f7 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Thu, 8 Mar 2018 16:18:18 -0800 Subject: [PATCH] Use events to tell host about syntax diagnostics Better decouple the language host from the language clients by using events instead of direct calls --- .../src/typeScriptServiceClientHost.ts | 10 +++++++--- extensions/typescript/src/typescriptService.ts | 3 --- .../typescript/src/typescriptServiceClient.ts | 18 +++++++++++++++--- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/extensions/typescript/src/typeScriptServiceClientHost.ts b/extensions/typescript/src/typeScriptServiceClientHost.ts index 29a50158bb4..fb4bded8896 100644 --- a/extensions/typescript/src/typeScriptServiceClientHost.ts +++ b/extensions/typescript/src/typeScriptServiceClientHost.ts @@ -71,6 +71,10 @@ export default class TypeScriptServiceClientHost implements ITypeScriptServiceCl this.client = new TypeScriptServiceClient(this, workspaceState, version => this.versionStatus.onDidChangeTypeScriptVersion(version), plugins, logDirectoryProvider); this.disposables.push(this.client); + this.client.onSyntaxDiagnosticsReceived(diag => this.syntaxDiagnosticsReceived(diag), null, this.disposables); + this.client.onSemanticDiagnosticsReceived(diag => this.semanticDiagnosticsReceived(diag), null, this.disposables); + this.client.onConfigDiagnosticsReceived(diag => this.configFileDiagnosticsReceived(diag), null, this.disposables); + this.versionStatus = new VersionStatus(resource => this.client.normalizePath(resource)); this.disposables.push(this.versionStatus); @@ -166,7 +170,7 @@ export default class TypeScriptServiceClientHost implements ITypeScriptServiceCl }); } - /* internal */ syntaxDiagnosticsReceived(event: Proto.DiagnosticEvent): void { + private syntaxDiagnosticsReceived(event: Proto.DiagnosticEvent): void { const body = event.body; if (body && body.diagnostics) { this.findLanguage(body.file).then(language => { @@ -177,7 +181,7 @@ export default class TypeScriptServiceClientHost implements ITypeScriptServiceCl } } - /* internal */ semanticDiagnosticsReceived(event: Proto.DiagnosticEvent): void { + private semanticDiagnosticsReceived(event: Proto.DiagnosticEvent): void { const body = event.body; if (body && body.diagnostics) { this.findLanguage(body.file).then(language => { @@ -188,7 +192,7 @@ export default class TypeScriptServiceClientHost implements ITypeScriptServiceCl } } - /* internal */ configFileDiagnosticsReceived(event: Proto.ConfigFileDiagnosticEvent): void { + private configFileDiagnosticsReceived(event: Proto.ConfigFileDiagnosticEvent): void { // See https://github.com/Microsoft/TypeScript/issues/10384 const body = event.body; if (!body || !body.diagnostics || !body.configFile) { diff --git a/extensions/typescript/src/typescriptService.ts b/extensions/typescript/src/typescriptService.ts index db51d60464c..a18b071e73d 100644 --- a/extensions/typescript/src/typescriptService.ts +++ b/extensions/typescript/src/typescriptService.ts @@ -12,9 +12,6 @@ import { TypeScriptServiceConfiguration } from './utils/configuration'; import Logger from './utils/logger'; export interface ITypeScriptServiceClientHost { - syntaxDiagnosticsReceived(event: Proto.DiagnosticEvent): void; - semanticDiagnosticsReceived(event: Proto.DiagnosticEvent): void; - configFileDiagnosticsReceived(event: Proto.ConfigFileDiagnosticEvent): void; populateService(): void; } diff --git a/extensions/typescript/src/typescriptServiceClient.ts b/extensions/typescript/src/typescriptServiceClient.ts index dc3a753210a..a10baa5ea61 100644 --- a/extensions/typescript/src/typescriptServiceClient.ts +++ b/extensions/typescript/src/typescriptServiceClient.ts @@ -233,6 +233,15 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient this.disposables.push(this.telemetryReporter); } + private _onSyntaxDiagnosticsReceived = new EventEmitter(); + public get onSyntaxDiagnosticsReceived(): Event { return this._onSyntaxDiagnosticsReceived.event; } + + private _onSemanticDiagnosticsReceived = new EventEmitter(); + public get onSemanticDiagnosticsReceived(): Event { return this._onSemanticDiagnosticsReceived.event; } + + private _onConfigDiagnosticsReceived = new EventEmitter(); + public get onConfigDiagnosticsReceived(): Event { return this._onConfigDiagnosticsReceived.event; } + public get configuration() { return this._configuration; } @@ -245,6 +254,9 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient } disposeAll(this.disposables); + this._onSyntaxDiagnosticsReceived.dispose(); + this._onSemanticDiagnosticsReceived.dispose(); + this._onConfigDiagnosticsReceived.dispose(); } public restartTsServer(): void { @@ -782,15 +794,15 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient private dispatchEvent(event: Proto.Event) { switch (event.event) { case 'syntaxDiag': - this.host.syntaxDiagnosticsReceived(event as Proto.DiagnosticEvent); + this._onSyntaxDiagnosticsReceived.fire(event as Proto.DiagnosticEvent); break; case 'semanticDiag': - this.host.semanticDiagnosticsReceived(event as Proto.DiagnosticEvent); + this._onSemanticDiagnosticsReceived.fire(event as Proto.DiagnosticEvent); break; case 'configFileDiag': - this.host.configFileDiagnosticsReceived(event as Proto.ConfigFileDiagnosticEvent); + this._onConfigDiagnosticsReceived.fire(event as Proto.ConfigFileDiagnosticEvent); break; case 'telemetry': -- GitLab