@@ -101,13 +101,7 @@ module ts.server {
101
101
}
102
102
103
103
getScriptFileNames ( ) {
104
- var filenames : string [ ] = [ ] ;
105
- for ( var filename in this . filenameToScript ) {
106
- if ( this . filenameToScript [ filename ] && this . filenameToScript [ filename ] . isOpen ) {
107
- filenames . push ( filename ) ;
108
- }
109
- }
110
- return filenames ;
104
+ return this . roots . map ( root => root . fileName ) ;
111
105
}
112
106
113
107
getScriptVersion ( filename : string ) {
@@ -536,15 +530,35 @@ module ts.server {
536
530
updateProjectStructure ( ) {
537
531
this . log ( "updating project structure from ..." , "Info" ) ;
538
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
+
539
+ var openFilesReferenced : ScriptInfo [ ] = [ ] ;
540
+ var unattachedOpenFiles : ScriptInfo [ ] = [ ] ;
541
+
539
542
for ( var i = 0 , len = this . openFilesReferenced . length ; i < len ; i ++ ) {
540
- var refdFile = this . openFilesReferenced [ i ] ;
541
- refdFile . defaultProject . updateGraph ( ) ;
542
- var sourceFile = refdFile . defaultProject . getSourceFile ( refdFile ) ;
543
- if ( ! sourceFile ) {
544
- this . openFilesReferenced = copyListRemovingItem ( refdFile , this . openFilesReferenced ) ;
545
- this . addOpenFile ( refdFile ) ;
543
+ var referencedFile = this . openFilesReferenced [ i ] ;
544
+ referencedFile . defaultProject . updateGraph ( ) ;
545
+ var sourceFile = referencedFile . defaultProject . getSourceFile ( referencedFile ) ;
546
+ if ( sourceFile ) {
547
+ openFilesReferenced . push ( referencedFile ) ;
548
+ }
549
+ else {
550
+ unattachedOpenFiles . push ( referencedFile ) ;
546
551
}
547
552
}
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.
548
562
var openFileRoots : ScriptInfo [ ] = [ ] ;
549
563
for ( var i = 0 , len = this . openFileRoots . length ; i < len ; i ++ ) {
550
564
var rootFile = this . openFileRoots [ i ] ;
@@ -555,12 +569,19 @@ module ts.server {
555
569
openFileRoots . push ( rootFile ) ;
556
570
}
557
571
else {
558
- // remove project from inferred projects list
572
+ // remove project from inferred projects list because root captured
559
573
this . inferredProjects = copyListRemovingItem ( rootedProject , this . inferredProjects ) ;
560
574
this . openFilesReferenced . push ( rootFile ) ;
561
575
}
562
576
}
563
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.
582
+ for ( var i = 0 , len = unattachedOpenFiles . length ; i < len ; i ++ ) {
583
+ this . addOpenFile ( unattachedOpenFiles [ i ] ) ;
584
+ }
564
585
this . printProjects ( ) ;
565
586
}
566
587
0 commit comments