@@ -878,10 +878,10 @@ namespace ts.server {
878
878
if ( info . hasMixedContent ) {
879
879
info . registerFileUpdate ( ) ;
880
880
}
881
- // last open file in configured project - close it
882
- if ( ( < ConfiguredProject > p ) . deleteOpenRef ( ) === 0 ) {
883
- ( projectsToRemove || ( projectsToRemove = [ ] ) ) . push ( p ) ;
884
- }
881
+ // Delete the reference to the open configured projects but
882
+ // do not remove the project so that we can reuse this project
883
+ // if it would need to be re-created with next file open
884
+ ( < ConfiguredProject > p ) . deleteOpenRef ( ) ;
885
885
}
886
886
else if ( p . projectKind === ProjectKind . Inferred && p . isRoot ( info ) ) {
887
887
// If this was the open root file of inferred project
@@ -1881,6 +1881,15 @@ namespace ts.server {
1881
1881
}
1882
1882
this . addToListOfOpenFiles ( info ) ;
1883
1883
1884
+ // Remove the configured projects that have zero references from open files.
1885
+ // This was postponed from closeOpenFile to after opening next file,
1886
+ // so that we can reuse the project if we need to right away
1887
+ this . configuredProjects . forEach ( project => {
1888
+ if ( ! project . hasOpenRef ( ) ) {
1889
+ this . removeProject ( project ) ;
1890
+ }
1891
+ } ) ;
1892
+
1884
1893
// Delete the orphan files here because there might be orphan script infos (which are not part of project)
1885
1894
// when some file/s were closed which resulted in project removal.
1886
1895
// It was then postponed to cleanup these script infos so that they can be reused if
0 commit comments