@@ -70,8 +70,8 @@ export default class TypeScriptServiceClientHost {
7070 this . client = new TypeScriptServiceClient ( workspaceState , version => this . versionStatus . onDidChangeTypeScriptVersion ( version ) , plugins , logDirectoryProvider ) ;
7171 this . disposables . push ( this . client ) ;
7272
73- this . client . onSyntaxDiagnosticsReceived ( diag => this . syntaxDiagnosticsReceived ( diag ) , null , this . disposables ) ;
74- this . client . onSemanticDiagnosticsReceived ( diag => this . semanticDiagnosticsReceived ( diag ) , null , this . disposables ) ;
73+ this . client . onSyntaxDiagnosticsReceived ( ( { file , diagnostics } ) => this . syntaxDiagnosticsReceived ( file , diagnostics ) , null , this . disposables ) ;
74+ this . client . onSemanticDiagnosticsReceived ( ( { file , diagnostics } ) => this . semanticDiagnosticsReceived ( file , diagnostics ) , null , this . disposables ) ;
7575 this . client . onConfigDiagnosticsReceived ( diag => this . configFileDiagnosticsReceived ( diag ) , null , this . disposables ) ;
7676 this . client . onResendModelsRequested ( ( ) => this . populateService ( ) , null , this . disposables ) ;
7777
@@ -170,25 +170,21 @@ export default class TypeScriptServiceClientHost {
170170 } ) ;
171171 }
172172
173- private syntaxDiagnosticsReceived ( event : Proto . DiagnosticEvent ) : void {
174- const body = event . body ;
175- if ( body && body . diagnostics ) {
176- this . findLanguage ( body . file ) . then ( language => {
177- if ( language ) {
178- language . syntaxDiagnosticsReceived ( this . client . asUrl ( body . file ) , this . createMarkerDatas ( body . diagnostics , language . diagnosticSource ) ) ;
179- }
180- } ) ;
173+ private async syntaxDiagnosticsReceived ( file : string , diagnostics : Proto . Diagnostic [ ] ) : Promise < void > {
174+ const language = await this . findLanguage ( file ) ;
175+ if ( language ) {
176+ language . syntaxDiagnosticsReceived (
177+ this . client . asUrl ( file ) ,
178+ this . createMarkerDatas ( diagnostics , language . diagnosticSource ) ) ;
181179 }
182180 }
183181
184- private semanticDiagnosticsReceived ( event : Proto . DiagnosticEvent ) : void {
185- const body = event . body ;
186- if ( body && body . diagnostics ) {
187- this . findLanguage ( body . file ) . then ( language => {
188- if ( language ) {
189- language . semanticDiagnosticsReceived ( this . client . asUrl ( body . file ) , this . createMarkerDatas ( body . diagnostics , language . diagnosticSource ) ) ;
190- }
191- } ) ;
182+ private async semanticDiagnosticsReceived ( file : string , diagnostics : Proto . Diagnostic [ ] ) : Promise < void > {
183+ const language = await this . findLanguage ( file ) ;
184+ if ( language ) {
185+ language . semanticDiagnosticsReceived (
186+ this . client . asUrl ( file ) ,
187+ this . createMarkerDatas ( diagnostics , language . diagnosticSource ) ) ;
192188 }
193189 }
194190
@@ -244,19 +240,19 @@ export default class TypeScriptServiceClientHost {
244240 }
245241
246242 private createMarkerDatas ( diagnostics : Proto . Diagnostic [ ] , source : string ) : Diagnostic [ ] {
247- const result : Diagnostic [ ] = [ ] ;
248- for ( const diagnostic of diagnostics ) {
249- const { start , end , text } = diagnostic ;
250- const range = new Range ( tsLocationToVsPosition ( start ) , tsLocationToVsPosition ( end ) ) ;
251- const converted = new Diagnostic ( range , text ) ;
252- converted . severity = this . getDiagnosticSeverity ( diagnostic ) ;
253- converted . source = diagnostic . source || source ;
254- if ( diagnostic . code ) {
255- converted . code = diagnostic . code ;
256- }
257- result . push ( converted ) ;
243+ return diagnostics . map ( tsDiag => this . tsDiagnosticToVsDiagnostic ( tsDiag , source ) ) ;
244+ }
245+
246+ private tsDiagnosticToVsDiagnostic ( diagnostic : Proto . Diagnostic , source : string ) {
247+ const { start , end , text } = diagnostic ;
248+ const range = new Range ( tsLocationToVsPosition ( start ) , tsLocationToVsPosition ( end ) ) ;
249+ const converted = new Diagnostic ( range , text ) ;
250+ converted . severity = this . getDiagnosticSeverity ( diagnostic ) ;
251+ converted . source = diagnostic . source || source ;
252+ if ( diagnostic . code ) {
253+ converted . code = diagnostic . code ;
258254 }
259- return result ;
255+ return converted ;
260256 }
261257
262258 private getDiagnosticSeverity ( diagnostic : Proto . Diagnostic ) : DiagnosticSeverity {
0 commit comments