@@ -530,8 +530,15 @@ module ts.server {
530
530
updateProjectStructure ( ) {
531
531
this . log ( "updating project structure from ..." , "Info" ) ;
532
532
this . printProjects ( ) ;
533
+
534
+ // First loop through all open files that are referenced by projects but are not
535
+ // project roots. For each referenced file, see if the default project still
536
+ // references that file. If so, then just keep the file in the referenced list.
537
+ // If not, add the file to an unattached list, to be rechecked later.
538
+
533
539
var openFilesReferenced : ScriptInfo [ ] = [ ] ;
534
540
var unattachedOpenFiles : ScriptInfo [ ] = [ ] ;
541
+
535
542
for ( var i = 0 , len = this . openFilesReferenced . length ; i < len ; i ++ ) {
536
543
var referencedFile = this . openFilesReferenced [ i ] ;
537
544
referencedFile . defaultProject . updateGraph ( ) ;
@@ -544,6 +551,14 @@ module ts.server {
544
551
}
545
552
}
546
553
this . openFilesReferenced = openFilesReferenced ;
554
+
555
+ // Then, loop through all of the open files that are project roots.
556
+ // For each root file, note the project that it roots. Then see if
557
+ // any other projects newly reference the file. If zero projects
558
+ // newly reference the file, keep it as a root. If one or more
559
+ // projects newly references the file, remove its project from the
560
+ // inferred projects list (since it is no longer a root) and add
561
+ // the file to the open, referenced file list.
547
562
var openFileRoots : ScriptInfo [ ] = [ ] ;
548
563
for ( var i = 0 , len = this . openFileRoots . length ; i < len ; i ++ ) {
549
564
var rootFile = this . openFileRoots [ i ] ;
@@ -560,6 +575,10 @@ module ts.server {
560
575
}
561
576
}
562
577
this . openFileRoots = openFileRoots ;
578
+
579
+ // Finally, if we found any open, referenced files that are no longer
580
+ // referenced by their default project, treat them as newly opened
581
+ // by the editor.
563
582
for ( var i = 0 , len = unattachedOpenFiles . length ; i < len ; i ++ ) {
564
583
this . addOpenFile ( unattachedOpenFiles [ i ] ) ;
565
584
}
0 commit comments