@@ -301,8 +301,7 @@ export function formatDiagnosticToProtocol(diag: Diagnostic, includeFileName: bo
301301
302302interface PendingErrorCheck {
303303 fileName : NormalizedPath ;
304- ranges ?: TextRange [ ] ;
305- project ?: Project ;
304+ project : Project ;
306305}
307306
308307function allEditsBeforePos ( edits : readonly TextChange [ ] , pos : number ) : boolean {
@@ -1143,7 +1142,7 @@ export class Session<TMessage = string> implements EventSender {
11431142 if ( ! this . suppressDiagnosticEvents && ! this . noGetErrOnBackgroundUpdate ) {
11441143 this . projectService . logger . info ( `Queueing diagnostics update for ${ openFiles } ` ) ;
11451144 // 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 ) ) ;
11471146 }
11481147
11491148 // Send project changed event
@@ -1336,7 +1335,7 @@ export class Session<TMessage = string> implements EventSender {
13361335 /** It is the caller's responsibility to verify that `!this.suppressDiagnosticEvents`. */
13371336 private updateErrorCheck (
13381337 next : NextStep ,
1339- checkList : PendingErrorCheck [ ] ,
1338+ checkList : PendingErrorCheck [ ] | ( string | protocol . FileRangesRequestArgs ) [ ] ,
13401339 ms : number ,
13411340 requireOpen = true ,
13421341 ) {
@@ -1363,8 +1362,7 @@ export class Session<TMessage = string> implements EventSender {
13631362 }
13641363
13651364 if ( this . getPreferences ( fileName ) . disableSuggestions ) {
1366- goNext ( ) ;
1367- return ;
1365+ return goNext ( ) ;
13681366 }
13691367 next . immediate ( "suggestionCheck" , ( ) => {
13701368 this . suggestionCheck ( fileName , project ) ;
@@ -1377,11 +1375,23 @@ export class Session<TMessage = string> implements EventSender {
13771375 return ;
13781376 }
13791377
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 ) ;
13831387 }
13841388
1389+ if ( ! item ) {
1390+ return goNext ( ) ;
1391+ }
1392+
1393+ const { fileName, project } = item ;
1394+
13851395 // Ensure the project is up to date before checking if this file is present in the project.
13861396 updateProjectIfDirty ( project ) ;
13871397 if ( ! project . containsFile ( fileName , requireOpen ) ) {
@@ -1395,13 +1405,16 @@ export class Session<TMessage = string> implements EventSender {
13951405
13961406 // Don't provide semantic diagnostics unless we're in full semantic mode.
13971407 if ( project . projectService . serverMode !== LanguageServiceMode . Semantic ) {
1398- goNext ( ) ;
1399- return ;
1408+ return goNext ( ) ;
14001409 }
14011410
1411+ // const ranges = checkList[index].ranges;
14021412 if ( ranges ) {
14031413 return next . immediate ( "regionSemanticCheck" , ( ) => {
1404- this . regionSemanticCheck ( fileName , project , ranges ) ;
1414+ const scriptInfo = this . projectService . getScriptInfoForNormalizedPath ( fileName ) ;
1415+ if ( scriptInfo ) {
1416+ this . regionSemanticCheck ( fileName , project , ranges . map ( range => this . getRange ( { file : fileName , ...range } , scriptInfo ) ) ) ;
1417+ }
14051418 if ( this . changeSeq !== seq ) {
14061419 return ;
14071420 }
@@ -2560,28 +2573,19 @@ export class Session<TMessage = string> implements EventSender {
25602573 }
25612574 }
25622575
2576+ private toPendingErrorCheck ( uncheckedFileName : string ) : PendingErrorCheck | undefined {
2577+ const fileName = toNormalizedPath ( uncheckedFileName ) ;
2578+ const project = this . projectService . tryGetDefaultProjectForFile ( fileName ) ;
2579+ return project && { fileName, project } ;
2580+ }
2581+
25632582 private getDiagnostics ( next : NextStep , delay : number , fileArgs : ( string | protocol . FileRangesRequestArgs ) [ ] ) : void {
25642583 if ( this . suppressDiagnosticEvents ) {
25652584 return ;
25662585 }
25672586
25682587 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 ) ;
2588+ this . updateErrorCheck ( next , fileArgs , delay ) ;
25852589 }
25862590 }
25872591
0 commit comments