提交 a3562fa1 编写于 作者: M Matt Bierner

Use events to tell host about syntax diagnostics

Better decouple the language host from the language clients by using events instead of direct calls
上级 ba44dc24
...@@ -71,6 +71,10 @@ export default class TypeScriptServiceClientHost implements ITypeScriptServiceCl ...@@ -71,6 +71,10 @@ export default class TypeScriptServiceClientHost implements ITypeScriptServiceCl
this.client = new TypeScriptServiceClient(this, workspaceState, version => this.versionStatus.onDidChangeTypeScriptVersion(version), plugins, logDirectoryProvider); this.client = new TypeScriptServiceClient(this, workspaceState, version => this.versionStatus.onDidChangeTypeScriptVersion(version), plugins, logDirectoryProvider);
this.disposables.push(this.client); 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.versionStatus = new VersionStatus(resource => this.client.normalizePath(resource));
this.disposables.push(this.versionStatus); this.disposables.push(this.versionStatus);
...@@ -166,7 +170,7 @@ export default class TypeScriptServiceClientHost implements ITypeScriptServiceCl ...@@ -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; const body = event.body;
if (body && body.diagnostics) { if (body && body.diagnostics) {
this.findLanguage(body.file).then(language => { this.findLanguage(body.file).then(language => {
...@@ -177,7 +181,7 @@ export default class TypeScriptServiceClientHost implements ITypeScriptServiceCl ...@@ -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; const body = event.body;
if (body && body.diagnostics) { if (body && body.diagnostics) {
this.findLanguage(body.file).then(language => { this.findLanguage(body.file).then(language => {
...@@ -188,7 +192,7 @@ export default class TypeScriptServiceClientHost implements ITypeScriptServiceCl ...@@ -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 // See https://github.com/Microsoft/TypeScript/issues/10384
const body = event.body; const body = event.body;
if (!body || !body.diagnostics || !body.configFile) { if (!body || !body.diagnostics || !body.configFile) {
......
...@@ -12,9 +12,6 @@ import { TypeScriptServiceConfiguration } from './utils/configuration'; ...@@ -12,9 +12,6 @@ import { TypeScriptServiceConfiguration } from './utils/configuration';
import Logger from './utils/logger'; import Logger from './utils/logger';
export interface ITypeScriptServiceClientHost { export interface ITypeScriptServiceClientHost {
syntaxDiagnosticsReceived(event: Proto.DiagnosticEvent): void;
semanticDiagnosticsReceived(event: Proto.DiagnosticEvent): void;
configFileDiagnosticsReceived(event: Proto.ConfigFileDiagnosticEvent): void;
populateService(): void; populateService(): void;
} }
......
...@@ -233,6 +233,15 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient ...@@ -233,6 +233,15 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
this.disposables.push(this.telemetryReporter); this.disposables.push(this.telemetryReporter);
} }
private _onSyntaxDiagnosticsReceived = new EventEmitter<Proto.DiagnosticEvent>();
public get onSyntaxDiagnosticsReceived(): Event<Proto.DiagnosticEvent> { return this._onSyntaxDiagnosticsReceived.event; }
private _onSemanticDiagnosticsReceived = new EventEmitter<Proto.DiagnosticEvent>();
public get onSemanticDiagnosticsReceived(): Event<Proto.DiagnosticEvent> { return this._onSemanticDiagnosticsReceived.event; }
private _onConfigDiagnosticsReceived = new EventEmitter<Proto.ConfigFileDiagnosticEvent>();
public get onConfigDiagnosticsReceived(): Event<Proto.ConfigFileDiagnosticEvent> { return this._onConfigDiagnosticsReceived.event; }
public get configuration() { public get configuration() {
return this._configuration; return this._configuration;
} }
...@@ -245,6 +254,9 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient ...@@ -245,6 +254,9 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
} }
disposeAll(this.disposables); disposeAll(this.disposables);
this._onSyntaxDiagnosticsReceived.dispose();
this._onSemanticDiagnosticsReceived.dispose();
this._onConfigDiagnosticsReceived.dispose();
} }
public restartTsServer(): void { public restartTsServer(): void {
...@@ -782,15 +794,15 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient ...@@ -782,15 +794,15 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
private dispatchEvent(event: Proto.Event) { private dispatchEvent(event: Proto.Event) {
switch (event.event) { switch (event.event) {
case 'syntaxDiag': case 'syntaxDiag':
this.host.syntaxDiagnosticsReceived(event as Proto.DiagnosticEvent); this._onSyntaxDiagnosticsReceived.fire(event as Proto.DiagnosticEvent);
break; break;
case 'semanticDiag': case 'semanticDiag':
this.host.semanticDiagnosticsReceived(event as Proto.DiagnosticEvent); this._onSemanticDiagnosticsReceived.fire(event as Proto.DiagnosticEvent);
break; break;
case 'configFileDiag': case 'configFileDiag':
this.host.configFileDiagnosticsReceived(event as Proto.ConfigFileDiagnosticEvent); this._onConfigDiagnosticsReceived.fire(event as Proto.ConfigFileDiagnosticEvent);
break; break;
case 'telemetry': case 'telemetry':
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册