@@ -19,8 +19,8 @@ namespace ts.server {
1919 }
2020
2121 export abstract class Project {
22- private readonly rootFiles : ScriptInfo [ ] = [ ] ;
23- private readonly rootFilesMap : FileMap < ScriptInfo > = createFileMap < ScriptInfo > ( ) ;
22+ private rootFiles : ScriptInfo [ ] = [ ] ;
23+ private rootFilesMap : FileMap < ScriptInfo > = createFileMap < ScriptInfo > ( ) ;
2424 private lsHost : ServerLanguageServiceHost ;
2525 private program : ts . Program ;
2626
@@ -96,11 +96,24 @@ namespace ts.server {
9696 abstract getProjectName ( ) : string ;
9797
9898 close ( ) {
99- for ( const fileName of this . getFileNames ( ) ) {
100- const info = this . projectService . getScriptInfoForNormalizedPath ( fileName ) ;
101- info . detachFromProject ( this ) ;
99+ if ( this . program ) {
100+ // if we have a program - release all files that are enlisted in program
101+ for ( const f of this . program . getSourceFiles ( ) ) {
102+ const info = this . projectService . getScriptInfo ( f . fileName ) ;
103+ info . detachFromProject ( this ) ;
104+ }
105+ }
106+ else {
107+ // release all root files
108+ for ( const root of this . rootFiles ) {
109+ root . detachFromProject ( this ) ;
110+ }
102111 }
103- // signal language service to release files acquired from document registry
112+ this . rootFiles = undefined ;
113+ this . rootFilesMap = undefined ;
114+ this . program = undefined ;
115+
116+ // signal language service to release source files acquired from document registry
104117 this . languageService . dispose ( ) ;
105118 }
106119
@@ -137,7 +150,7 @@ namespace ts.server {
137150 }
138151
139152 containsScriptInfo ( info : ScriptInfo ) : boolean {
140- return this . program && this . program . getSourceFileByPath ( info . path ) !== undefined ;
153+ return this . isRoot ( info ) || ( this . program && this . program . getSourceFileByPath ( info . path ) !== undefined ) ;
141154 }
142155
143156 containsFile ( filename : NormalizedPath , requireOpen ?: boolean ) {
0 commit comments