@@ -719,10 +719,8 @@ namespace ts.server {
719
719
this . projectService . logger . info ( `got projects updated in background, updating diagnostics for ${ openFiles } ` ) ;
720
720
if ( openFiles . length ) {
721
721
if ( ! this . suppressDiagnosticEvents && ! this . noGetErrOnBackgroundUpdate ) {
722
- const checkList = this . createCheckList ( openFiles ) ;
723
-
724
722
// For now only queue error checking for open files. We can change this to include non open files as well
725
- this . errorCheck . startNew ( next => this . updateErrorCheck ( next , checkList , 100 , /*requireOpen*/ true ) ) ;
723
+ this . errorCheck . startNew ( next => this . updateErrorCheck ( next , openFiles , 100 , /*requireOpen*/ true ) ) ;
726
724
}
727
725
728
726
// Send project changed event
@@ -870,20 +868,37 @@ namespace ts.server {
870
868
}
871
869
872
870
/** It is the caller's responsibility to verify that `!this.suppressDiagnosticEvents`. */
873
- private updateErrorCheck ( next : NextStep , checkList : PendingErrorCheck [ ] , ms : number , requireOpen = true ) {
871
+ private updateErrorCheck ( next : NextStep , checkList : readonly string [ ] | readonly PendingErrorCheck [ ] , ms : number , requireOpen = true ) {
874
872
Debug . assert ( ! this . suppressDiagnosticEvents ) ; // Caller's responsibility
875
873
876
874
const seq = this . changeSeq ;
877
875
const followMs = Math . min ( ms , 200 ) ;
878
876
879
877
let index = 0 ;
878
+ const goNext = ( ) => {
879
+ index ++ ;
880
+ if ( checkList . length > index ) {
881
+ next . delay ( followMs , checkOne ) ;
882
+ }
883
+ } ;
880
884
const checkOne = ( ) => {
881
885
if ( this . changeSeq !== seq ) {
882
886
return ;
883
887
}
884
888
885
- const { fileName, project } = checkList [ index ] ;
886
- index ++ ;
889
+ let item : string | PendingErrorCheck | undefined = checkList [ index ] ;
890
+ if ( isString ( item ) ) {
891
+ // Find out project for the file name
892
+ item = this . toPendingErrorCheck ( item ) ;
893
+ if ( ! item ) {
894
+ // Ignore file if there is no project for the file
895
+ goNext ( ) ;
896
+ return ;
897
+ }
898
+ }
899
+
900
+ const { fileName, project } = item ;
901
+
887
902
// Ensure the project is upto date before checking if this file is present in the project
888
903
updateProjectIfDirty ( project ) ;
889
904
if ( ! project . containsFile ( fileName , requireOpen ) ) {
@@ -901,11 +916,6 @@ namespace ts.server {
901
916
return ;
902
917
}
903
918
904
- const goNext = ( ) => {
905
- if ( checkList . length > index ) {
906
- next . delay ( followMs , checkOne ) ;
907
- }
908
- } ;
909
919
if ( this . getPreferences ( fileName ) . disableSuggestions ) {
910
920
goNext ( ) ;
911
921
}
@@ -1727,22 +1737,19 @@ namespace ts.server {
1727
1737
}
1728
1738
}
1729
1739
1730
- private createCheckList ( fileNames : string [ ] ) : PendingErrorCheck [ ] {
1731
- return mapDefined < string , PendingErrorCheck > ( fileNames , uncheckedFileName => {
1732
- const fileName = toNormalizedPath ( uncheckedFileName ) ;
1733
- const project = this . projectService . tryGetDefaultProjectForFile ( fileName ) ;
1734
- return project && { fileName, project } ;
1735
- } ) ;
1740
+ private toPendingErrorCheck ( uncheckedFileName : string ) : PendingErrorCheck | undefined {
1741
+ const fileName = toNormalizedPath ( uncheckedFileName ) ;
1742
+ const project = this . projectService . tryGetDefaultProjectForFile ( fileName ) ;
1743
+ return project && { fileName, project } ;
1736
1744
}
1737
1745
1738
1746
private getDiagnostics ( next : NextStep , delay : number , fileNames : string [ ] ) : void {
1739
1747
if ( this . suppressDiagnosticEvents ) {
1740
1748
return ;
1741
1749
}
1742
1750
1743
- const checkList = this . createCheckList ( fileNames ) ;
1744
- if ( checkList . length > 0 ) {
1745
- this . updateErrorCheck ( next , checkList , delay ) ;
1751
+ if ( fileNames . length > 0 ) {
1752
+ this . updateErrorCheck ( next , fileNames , delay ) ;
1746
1753
}
1747
1754
}
1748
1755
0 commit comments