@@ -878,10 +878,10 @@ namespace ts.server {
878878 if ( info . hasMixedContent ) {
879879 info . registerFileUpdate ( ) ;
880880 }
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 ( ) ;
885885 }
886886 else if ( p . projectKind === ProjectKind . Inferred && p . isRoot ( info ) ) {
887887 // If this was the open root file of inferred project
@@ -1881,6 +1881,15 @@ namespace ts.server {
18811881 }
18821882 this . addToListOfOpenFiles ( info ) ;
18831883
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+
18841893 // Delete the orphan files here because there might be orphan script infos (which are not part of project)
18851894 // when some file/s were closed which resulted in project removal.
18861895 // It was then postponed to cleanup these script infos so that they can be reused if
0 commit comments