@@ -725,15 +725,6 @@ namespace ts.server {
725
725
}
726
726
}
727
727
728
- private findContainingExternalProject ( fileName : NormalizedPath ) : ExternalProject {
729
- for ( const proj of this . externalProjects ) {
730
- if ( proj . containsFile ( fileName ) ) {
731
- return proj ;
732
- }
733
- }
734
- return undefined ;
735
- }
736
-
737
728
getFormatCodeOptions ( file ?: NormalizedPath ) {
738
729
let formatCodeSettings : FormatCodeSettings ;
739
730
if ( file ) {
@@ -1991,13 +1982,24 @@ namespace ts.server {
1991
1982
return this . openClientFileWithNormalizedPath ( toNormalizedPath ( fileName ) , fileContent , scriptKind , /*hasMixedContent*/ false , projectRootPath ? toNormalizedPath ( projectRootPath ) : undefined ) ;
1992
1983
}
1993
1984
1985
+ private findExternalProjetContainingOpenScriptInfo ( info : ScriptInfo ) : ExternalProject {
1986
+ for ( const proj of this . externalProjects ) {
1987
+ // Ensure project structure is uptodate to check if info is present in external project
1988
+ proj . updateGraph ( ) ;
1989
+ if ( proj . containsScriptInfo ( info ) ) {
1990
+ return proj ;
1991
+ }
1992
+ }
1993
+ return undefined ;
1994
+ }
1995
+
1994
1996
openClientFileWithNormalizedPath ( fileName : NormalizedPath , fileContent ?: string , scriptKind ?: ScriptKind , hasMixedContent ?: boolean , projectRootPath ?: NormalizedPath ) : OpenConfiguredProjectResult {
1995
1997
let configFileName : NormalizedPath ;
1996
1998
let sendConfigFileDiagEvent = false ;
1997
1999
let configFileErrors : ReadonlyArray < Diagnostic > ;
1998
2000
1999
2001
const info = this . getOrCreateScriptInfoOpenedByClientForNormalizedPath ( fileName , projectRootPath ? this . getNormalizedAbsolutePath ( projectRootPath ) : this . currentDirectory , fileContent , scriptKind , hasMixedContent ) ;
2000
- let project : ConfiguredProject | ExternalProject = this . findContainingExternalProject ( fileName ) ;
2002
+ let project : ConfiguredProject | ExternalProject = this . findExternalProjetContainingOpenScriptInfo ( info ) ;
2001
2003
if ( ! project ) {
2002
2004
configFileName = this . getConfigFileNameForFile ( info , projectRootPath ) ;
2003
2005
if ( configFileName ) {
@@ -2007,6 +2009,10 @@ namespace ts.server {
2007
2009
// Send the event only if the project got created as part of this open request
2008
2010
sendConfigFileDiagEvent = true ;
2009
2011
}
2012
+ else {
2013
+ // Ensure project is ready to check if it contains opened script info
2014
+ project . updateGraph ( ) ;
2015
+ }
2010
2016
}
2011
2017
}
2012
2018
if ( project && ! project . languageServiceEnabled ) {
0 commit comments