@@ -337,7 +337,7 @@ namespace ts.server {
337337 case ContextEvent :
338338 const { project, fileName } = event . data ;
339339 this . projectService . logger . info ( `got context event, updating diagnostics for ${ fileName } ` ) ;
340- this . errorCheck . startNew ( next => this . updateErrorCheck ( next , [ { fileName, project } ] , this . changeSeq , ( n ) => n === this . changeSeq , 100 ) ) ;
340+ this . errorCheck . startNew ( next => this . updateErrorCheck ( next , [ { fileName, project } ] , 100 ) ) ;
341341 break ;
342342 case ConfigFileDiagEvent :
343343 const { triggerFile, configFileName, diagnostics } = event . data ;
@@ -453,22 +453,23 @@ namespace ts.server {
453453 }
454454 }
455455
456- private updateProjectStructure ( seq : number , matchSeq : ( seq : number ) => boolean , ms = 1500 ) {
456+ private updateProjectStructure ( ) {
457+ const ms = 1500 ;
458+ const seq = this . changeSeq ;
457459 this . host . setTimeout ( ( ) => {
458- if ( matchSeq ( seq ) ) {
460+ if ( this . changeSeq === seq ) {
459461 this . projectService . refreshInferredProjects ( ) ;
460462 }
461463 } , ms ) ;
462464 }
463465
464- private updateErrorCheck ( next : NextStep , checkList : PendingErrorCheck [ ] , seq : number , matchSeq : ( seq : number ) => boolean , ms = 1500 , followMs = 200 , requireOpen = true ) {
465- if ( followMs > ms ) {
466- followMs = ms ;
467- }
466+ private updateErrorCheck ( next : NextStep , checkList : PendingErrorCheck [ ] , ms : number , requireOpen = true ) {
467+ const seq = this . changeSeq ;
468+ const followMs = Math . min ( ms , 200 ) ;
468469
469470 let index = 0 ;
470471 const checkOne = ( ) => {
471- if ( matchSeq ( seq ) ) {
472+ if ( this . changeSeq === seq ) {
472473 const checkSpec = checkList [ index ] ;
473474 index ++ ;
474475 if ( checkSpec . project . containsFile ( checkSpec . fileName , requireOpen ) ) {
@@ -483,7 +484,7 @@ namespace ts.server {
483484 }
484485 } ;
485486
486- if ( ( checkList . length > index ) && ( matchSeq ( seq ) ) ) {
487+ if ( checkList . length > index && this . changeSeq === seq ) {
487488 next . delay ( ms , checkOne ) ;
488489 }
489490 }
@@ -1262,14 +1263,14 @@ namespace ts.server {
12621263 }
12631264
12641265 private getDiagnostics ( next : NextStep , delay : number , fileNames : string [ ] ) : void {
1265- const checkList = mapDefined ( fileNames , uncheckedFileName => {
1266+ const checkList = mapDefined < string , PendingErrorCheck > ( fileNames , uncheckedFileName => {
12661267 const fileName = toNormalizedPath ( uncheckedFileName ) ;
12671268 const project = this . projectService . getDefaultProjectForFile ( fileName , /*refreshInferredProjects*/ true ) ;
12681269 return project && { fileName, project } ;
12691270 } ) ;
12701271
12711272 if ( checkList . length > 0 ) {
1272- this . updateErrorCheck ( next , checkList , this . changeSeq , ( n ) => n === this . changeSeq , delay ) ;
1273+ this . updateErrorCheck ( next , checkList , delay ) ;
12731274 }
12741275 }
12751276
@@ -1283,7 +1284,7 @@ namespace ts.server {
12831284 scriptInfo . editContent ( start , end , args . insertString ) ;
12841285 this . changeSeq ++ ;
12851286 }
1286- this . updateProjectStructure ( this . changeSeq , n => n === this . changeSeq ) ;
1287+ this . updateProjectStructure ( ) ;
12871288 }
12881289 }
12891290
@@ -1638,7 +1639,7 @@ namespace ts.server {
16381639 const checkList = fileNamesInProject . map ( fileName => ( { fileName, project } ) ) ;
16391640 // Project level error analysis runs on background files too, therefore
16401641 // doesn't require the file to be opened
1641- this . updateErrorCheck ( next , checkList , this . changeSeq , ( n ) => n === this . changeSeq , delay , 200 , /*requireOpen*/ false ) ;
1642+ this . updateErrorCheck ( next , checkList , delay , /*requireOpen*/ false ) ;
16421643 }
16431644 }
16441645
0 commit comments