@@ -1238,40 +1238,43 @@ namespace ts.server {
12381238 // close existing project and later we'll open a set of configured projects for these files
12391239 this . closeExternalProject ( proj . projectFileName , /*suppressRefresh*/ true ) ;
12401240 }
1241- else if ( this . externalProjectToConfiguredProjectMap . get ( proj . projectFileName ) ) {
1242- // this project used to include config files
1243- if ( ! tsConfigFiles ) {
1244- // config files were removed from the project - close existing external project which in turn will close configured projects
1245- this . closeExternalProject ( proj . projectFileName , /*suppressRefresh*/ true ) ;
1246- }
1247- else {
1248- // project previously had some config files - compare them with new set of files and close all configured projects that correspond to unused files
1249- const oldConfigFiles = this . externalProjectToConfiguredProjectMap . get ( proj . projectFileName ) ;
1250- let iNew = 0 ;
1251- let iOld = 0 ;
1252- while ( iNew < tsConfigFiles . length && iOld < oldConfigFiles . length ) {
1253- const newConfig = tsConfigFiles [ iNew ] ;
1254- const oldConfig = oldConfigFiles [ iOld ] ;
1255- if ( oldConfig < newConfig ) {
1256- this . closeConfiguredProject ( oldConfig ) ;
1257- iOld ++ ;
1258- }
1259- else if ( oldConfig > newConfig ) {
1260- iNew ++ ;
1241+ else {
1242+ const oldConfigFiles = this . externalProjectToConfiguredProjectMap . get ( proj . projectFileName ) ;
1243+ if ( oldConfigFiles ) {
1244+ // this project used to include config files
1245+ if ( ! tsConfigFiles ) {
1246+ // config files were removed from the project - close existing external project which in turn will close configured projects
1247+ this . closeExternalProject ( proj . projectFileName , /*suppressRefresh*/ true ) ;
1248+ }
1249+ else {
1250+ // project previously had some config files - compare them with new set of files and close all configured projects that correspond to unused files
1251+ let iNew = 0 ;
1252+ let iOld = 0 ;
1253+ while ( iNew < tsConfigFiles . length && iOld < oldConfigFiles . length ) {
1254+ const newConfig = tsConfigFiles [ iNew ] ;
1255+ const oldConfig = oldConfigFiles [ iOld ] ;
1256+ if ( oldConfig < newConfig ) {
1257+ this . closeConfiguredProject ( oldConfig ) ;
1258+ iOld ++ ;
1259+ }
1260+ else if ( oldConfig > newConfig ) {
1261+ iNew ++ ;
1262+ }
1263+ else {
1264+ // record existing config files so avoid extra add-refs
1265+ ( exisingConfigFiles || ( exisingConfigFiles = [ ] ) ) . push ( oldConfig ) ;
1266+ iOld ++ ;
1267+ iNew ++ ;
1268+ }
12611269 }
1262- else {
1263- // record existing config files so avoid extra add-refs
1264- ( exisingConfigFiles || ( exisingConfigFiles = [ ] ) ) . push ( oldConfig ) ;
1265- iOld ++ ;
1266- iNew ++ ;
1270+ for ( let i = iOld ; i < oldConfigFiles . length ; i ++ ) {
1271+ // projects for all remaining old config files should be closed
1272+ this . closeConfiguredProject ( oldConfigFiles [ i ] ) ;
12671273 }
12681274 }
1269- for ( let i = iOld ; i < oldConfigFiles . length ; i ++ ) {
1270- // projects for all remaining old config files should be closed
1271- this . closeConfiguredProject ( oldConfigFiles [ i ] ) ;
1272- }
12731275 }
12741276 }
1277+
12751278 if ( tsConfigFiles ) {
12761279 // store the list of tsconfig files that belong to the external project
12771280 this . externalProjectToConfiguredProjectMap . set ( proj . projectFileName , tsConfigFiles ) ;
0 commit comments