@@ -666,18 +666,23 @@ namespace ts.server {
666666 // when creation inferred project for some file has added other open files into this project (i.e. as referenced files)
667667 // we definitely don't want to delete the project that was just created
668668 for ( const f of this . openFiles ) {
669- if ( f . containingProjects . length === 0 ) {
669+ if ( f . containingProjects . length === 0 || ! inferredProject . containsScriptInfo ( f ) ) {
670670 // this is orphaned file that we have not processed yet - skip it
671671 continue ;
672672 }
673- const defaultProject = f . getDefaultProject ( ) ;
674- if ( isRootFileInInferredProject ( info ) && defaultProject !== inferredProject && inferredProject . containsScriptInfo ( f ) ) {
675- // open file used to be root in inferred project,
676- // this inferred project is different from the one we've just created for current file
677- // and new inferred project references this open file.
678- // We should delete old inferred project and attach open file to the new one
679- this . removeProject ( defaultProject ) ;
680- f . attachToProject ( inferredProject ) ;
673+
674+ for ( const fContainingProject of f . containingProjects ) {
675+ if ( fContainingProject . projectKind === ProjectKind . Inferred &&
676+ fContainingProject . isRoot ( f ) &&
677+ fContainingProject !== inferredProject ) {
678+
679+ // open file used to be root in inferred project,
680+ // this inferred project is different from the one we've just created for current file
681+ // and new inferred project references this open file.
682+ // We should delete old inferred project and attach open file to the new one
683+ this . removeProject ( fContainingProject ) ;
684+ f . attachToProject ( inferredProject ) ;
685+ }
681686 }
682687 }
683688 }
0 commit comments