@@ -233,9 +233,9 @@ namespace ts.server {
233
233
this . realpath = path => host . realpath ( path ) ;
234
234
}
235
235
236
- this . languageService = createLanguageService ( this , this . documentRegistry ) ;
237
236
// Use the current directory as resolution root only if the project created using current directory string
238
237
this . resolutionCache = createResolutionCache ( this , currentDirectory && this . currentDirectory ) ;
238
+ this . languageService = createLanguageService ( this , this . documentRegistry ) ;
239
239
if ( ! languageServiceEnabled ) {
240
240
this . disableLanguageService ( ) ;
241
241
}
@@ -498,25 +498,23 @@ namespace ts.server {
498
498
499
499
close ( ) {
500
500
if ( this . program ) {
501
- // if we have a program - release all files that are enlisted in program
501
+ // if we have a program - release all files that are enlisted in program but arent root
502
+ // The releasing of the roots happens later
503
+ // The project could have pending update remaining and hence the info could be in the files but not in program graph
502
504
for ( const f of this . program . getSourceFiles ( ) ) {
503
- const info = this . projectService . getScriptInfo ( f . fileName ) ;
504
- // We might not find the script info in case its not associated with the project any more
505
- // and project graph was not updated (eg delayed update graph in case of files changed/deleted on the disk)
506
- if ( info ) {
507
- info . detachFromProject ( this ) ;
508
- }
505
+ this . detachScriptInfoIfNotRoot ( f . fileName ) ;
509
506
}
510
507
}
511
- if ( ! this . program || ! this . languageServiceEnabled ) {
512
- // release all root files either if there is no program or language service is disabled.
513
- // in the latter case set of root files can be larger than the set of files in program.
514
- for ( const root of this . rootFiles ) {
515
- root . detachFromProject ( this ) ;
516
- }
508
+ // Release external files
509
+ forEach ( this . externalFiles , externalFile => this . detachScriptInfoIfNotRoot ( externalFile ) ) ;
510
+ // Always remove root files from the project
511
+ for ( const root of this . rootFiles ) {
512
+ root . detachFromProject ( this ) ;
517
513
}
514
+
518
515
this . rootFiles = undefined ;
519
516
this . rootFilesMap = undefined ;
517
+ this . externalFiles = undefined ;
520
518
this . program = undefined ;
521
519
this . builder = undefined ;
522
520
this . resolutionCache . clear ( ) ;
@@ -535,6 +533,15 @@ namespace ts.server {
535
533
this . languageService = undefined ;
536
534
}
537
535
536
+ private detachScriptInfoIfNotRoot ( uncheckedFilename : string ) {
537
+ const info = this . projectService . getScriptInfo ( uncheckedFilename ) ;
538
+ // We might not find the script info in case its not associated with the project any more
539
+ // and project graph was not updated (eg delayed update graph in case of files changed/deleted on the disk)
540
+ if ( info && ! this . isRoot ( info ) ) {
541
+ info . detachFromProject ( this ) ;
542
+ }
543
+ }
544
+
538
545
isClosed ( ) {
539
546
return this . rootFiles === undefined ;
540
547
}
@@ -735,7 +742,6 @@ namespace ts.server {
735
742
*/
736
743
updateGraph ( ) : boolean {
737
744
this . resolutionCache . startRecordingFilesWithChangedResolutions ( ) ;
738
- this . hasInvalidatedResolution = this . resolutionCache . createHasInvalidatedResolution ( ) ;
739
745
740
746
let hasChanges = this . updateGraphWorker ( ) ;
741
747
@@ -795,9 +801,10 @@ namespace ts.server {
795
801
796
802
private updateGraphWorker ( ) {
797
803
const oldProgram = this . program ;
798
-
804
+ Debug . assert ( ! this . isClosed ( ) , "Called update graph worker of closed project" ) ;
799
805
this . writeLog ( `Starting updateGraphWorker: Project: ${ this . getProjectName ( ) } ` ) ;
800
806
const start = timestamp ( ) ;
807
+ this . hasInvalidatedResolution = this . resolutionCache . createHasInvalidatedResolution ( ) ;
801
808
this . resolutionCache . startCachingPerDirectoryResolution ( ) ;
802
809
this . program = this . languageService . getProgram ( ) ;
803
810
this . resolutionCache . finishCachingPerDirectoryResolution ( ) ;
@@ -1320,14 +1327,13 @@ namespace ts.server {
1320
1327
}
1321
1328
1322
1329
close ( ) {
1323
- super . close ( ) ;
1324
-
1325
1330
if ( this . configFileWatcher ) {
1326
1331
this . configFileWatcher . close ( ) ;
1327
1332
this . configFileWatcher = undefined ;
1328
1333
}
1329
1334
1330
1335
this . stopWatchingWildCards ( ) ;
1336
+ super . close ( ) ;
1331
1337
}
1332
1338
1333
1339
addOpenRef ( ) {
0 commit comments