@@ -301,8 +301,7 @@ export function formatDiagnosticToProtocol(diag: Diagnostic, includeFileName: bo
301
301
302
302
interface PendingErrorCheck {
303
303
fileName : NormalizedPath ;
304
- ranges ?: TextRange [ ] ;
305
- project ?: Project ;
304
+ project : Project ;
306
305
}
307
306
308
307
function allEditsBeforePos ( edits : readonly TextChange [ ] , pos : number ) : boolean {
@@ -1143,7 +1142,7 @@ export class Session<TMessage = string> implements EventSender {
1143
1142
if ( ! this . suppressDiagnosticEvents && ! this . noGetErrOnBackgroundUpdate ) {
1144
1143
this . projectService . logger . info ( `Queueing diagnostics update for ${ openFiles } ` ) ;
1145
1144
// For now only queue error checking for open files. We can change this to include non open files as well
1146
- this . errorCheck . startNew ( next => this . updateErrorCheck ( next , mapDefined ( openFiles , file => ( { fileName : toNormalizedPath ( file ) } ) ) , 100 , /*requireOpen*/ true ) ) ;
1145
+ this . errorCheck . startNew ( next => this . updateErrorCheck ( next , openFiles , 100 , /*requireOpen*/ true ) ) ;
1147
1146
}
1148
1147
1149
1148
// Send project changed event
@@ -1336,7 +1335,7 @@ export class Session<TMessage = string> implements EventSender {
1336
1335
/** It is the caller's responsibility to verify that `!this.suppressDiagnosticEvents`. */
1337
1336
private updateErrorCheck (
1338
1337
next : NextStep ,
1339
- checkList : PendingErrorCheck [ ] ,
1338
+ checkList : PendingErrorCheck [ ] | ( string | protocol . FileRangesRequestArgs ) [ ] ,
1340
1339
ms : number ,
1341
1340
requireOpen = true ,
1342
1341
) {
@@ -1363,8 +1362,7 @@ export class Session<TMessage = string> implements EventSender {
1363
1362
}
1364
1363
1365
1364
if ( this . getPreferences ( fileName ) . disableSuggestions ) {
1366
- goNext ( ) ;
1367
- return ;
1365
+ return goNext ( ) ;
1368
1366
}
1369
1367
next . immediate ( "suggestionCheck" , ( ) => {
1370
1368
this . suggestionCheck ( fileName , project ) ;
@@ -1377,11 +1375,23 @@ export class Session<TMessage = string> implements EventSender {
1377
1375
return ;
1378
1376
}
1379
1377
1380
- const { fileName, project = this . projectService . tryGetDefaultProjectForFile ( fileName ) , ranges } = checkList [ index ] ;
1381
- if ( ! project ) {
1382
- return ;
1378
+ let ranges : protocol . FileRange [ ] | undefined ;
1379
+ let item : string | protocol . FileRangesRequestArgs | PendingErrorCheck | undefined = checkList [ index ] ;
1380
+ if ( isString ( item ) ) {
1381
+ item = this . toPendingErrorCheck ( item ) ;
1382
+ }
1383
+ // eslint-disable-next-line local/no-in-operator
1384
+ else if ( "ranges" in item ) {
1385
+ ranges = item . ranges ;
1386
+ item = this . toPendingErrorCheck ( item . file ) ;
1383
1387
}
1384
1388
1389
+ if ( ! item ) {
1390
+ return goNext ( ) ;
1391
+ }
1392
+
1393
+ const { fileName, project } = item ;
1394
+
1385
1395
// Ensure the project is up to date before checking if this file is present in the project.
1386
1396
updateProjectIfDirty ( project ) ;
1387
1397
if ( ! project . containsFile ( fileName , requireOpen ) ) {
@@ -1395,13 +1405,15 @@ export class Session<TMessage = string> implements EventSender {
1395
1405
1396
1406
// Don't provide semantic diagnostics unless we're in full semantic mode.
1397
1407
if ( project . projectService . serverMode !== LanguageServiceMode . Semantic ) {
1398
- goNext ( ) ;
1399
- return ;
1408
+ return goNext ( ) ;
1400
1409
}
1401
1410
1402
1411
if ( ranges ) {
1403
1412
return next . immediate ( "regionSemanticCheck" , ( ) => {
1404
- this . regionSemanticCheck ( fileName , project , ranges ) ;
1413
+ const scriptInfo = this . projectService . getScriptInfoForNormalizedPath ( fileName ) ;
1414
+ if ( scriptInfo ) {
1415
+ this . regionSemanticCheck ( fileName , project , ranges . map ( range => this . getRange ( { file : fileName , ...range } , scriptInfo ) ) ) ;
1416
+ }
1405
1417
if ( this . changeSeq !== seq ) {
1406
1418
return ;
1407
1419
}
@@ -2560,28 +2572,19 @@ export class Session<TMessage = string> implements EventSender {
2560
2572
}
2561
2573
}
2562
2574
2575
+ private toPendingErrorCheck ( uncheckedFileName : string ) : PendingErrorCheck | undefined {
2576
+ const fileName = toNormalizedPath ( uncheckedFileName ) ;
2577
+ const project = this . projectService . tryGetDefaultProjectForFile ( fileName ) ;
2578
+ return project && { fileName, project } ;
2579
+ }
2580
+
2563
2581
private getDiagnostics ( next : NextStep , delay : number , fileArgs : ( string | protocol . FileRangesRequestArgs ) [ ] ) : void {
2564
2582
if ( this . suppressDiagnosticEvents ) {
2565
2583
return ;
2566
2584
}
2567
2585
2568
2586
if ( fileArgs . length > 0 ) {
2569
- const files = mapDefined ( fileArgs , fileArg => {
2570
- if ( isString ( fileArg ) ) {
2571
- return { fileName : toNormalizedPath ( fileArg ) } ;
2572
- }
2573
- const fileName = toNormalizedPath ( fileArg . file ) ;
2574
- const scriptInfo = this . projectService . getScriptInfo ( fileName ) ;
2575
- if ( ! scriptInfo ) {
2576
- return undefined ;
2577
- }
2578
- const ranges = fileArg . ranges . map ( range => this . getRange ( { file : fileArg . file , ...range } , scriptInfo ) ) ;
2579
- return {
2580
- fileName,
2581
- ranges,
2582
- } ;
2583
- } ) ;
2584
- this . updateErrorCheck ( next , files , delay ) ;
2587
+ this . updateErrorCheck ( next , fileArgs , delay ) ;
2585
2588
}
2586
2589
}
2587
2590
0 commit comments