@@ -713,6 +713,8 @@ function isAncestorConfigFileInfo(infoOrFileNameOrConfig: OpenScriptInfoOrClosed
713713export enum ConfiguredProjectLoadKind {
714714 FindOptimized ,
715715 Find ,
716+ CreateReplayOptimized ,
717+ CreateReplay ,
716718 CreateOptimized ,
717719 Create ,
718720 ReloadOptimized ,
@@ -721,11 +723,13 @@ export enum ConfiguredProjectLoadKind {
721723
722724type ConguredProjectLoadFindCreateOrReload =
723725 | ConfiguredProjectLoadKind . Find
726+ | ConfiguredProjectLoadKind . CreateReplay
724727 | ConfiguredProjectLoadKind . Create
725728 | ConfiguredProjectLoadKind . Reload ;
726729
727730type ConguredProjectLoadFindCreateOrReloadOptimized =
728731 | ConfiguredProjectLoadKind . FindOptimized
732+ | ConfiguredProjectLoadKind . CreateReplayOptimized
729733 | ConfiguredProjectLoadKind . CreateOptimized
730734 | ConfiguredProjectLoadKind . ReloadOptimized ;
731735
@@ -794,8 +798,7 @@ function forEachAncestorProjectLoad<T>(
794798 configFileInfo : true ,
795799 isForDefaultProject : ! searchOnlyPotentialSolution ,
796800 } ,
797- kind === ConfiguredProjectLoadKind . Find ||
798- kind === ConfiguredProjectLoadKind . FindOptimized ,
801+ kind <= ConfiguredProjectLoadKind . CreateReplay ,
799802 ) ;
800803 if ( ! configFileName ) return ;
801804
@@ -865,21 +868,28 @@ function forEachResolvedProjectReferenceProjectLoad<T>(
865868 configFileExistenceInfo ?. exists || project . resolvedChildConfigs ?. has ( childCanonicalConfigPath ) ?
866869 configFileExistenceInfo ! . config ! . parsedCommandLine : undefined :
867870 project . getParsedCommandLine ( childConfigName ) ;
868- if ( childConfig && loadKind !== kind ) {
871+ if ( childConfig && loadKind !== kind && loadKind > ConfiguredProjectLoadKind . CreateReplayOptimized ) {
869872 // If this was found using find: ensure this is uptodate if looking for creating or reloading
870873 childConfig = project . getParsedCommandLine ( childConfigName ) ;
871874 }
872875 if ( ! childConfig ) return undefined ;
873876
874877 // Find the project
875878 const childProject = project . projectService . findConfiguredProjectByProjectName ( childConfigName , allowDeferredClosed ) ;
879+ // Ignore if we couldnt find child project or config file existence info
880+ if (
881+ loadKind === ConfiguredProjectLoadKind . CreateReplayOptimized &&
882+ ! configFileExistenceInfo &&
883+ ! childProject
884+ ) return undefined ;
876885 switch ( loadKind ) {
877886 case ConfiguredProjectLoadKind . ReloadOptimized :
878887 if ( childProject ) childProject . projectService . reloadConfiguredProjectOptimized ( childProject , reason , reloadedProjects ! ) ;
879888 // falls through
880889 case ConfiguredProjectLoadKind . CreateOptimized :
881890 ( project . resolvedChildConfigs ??= new Set ( ) ) . add ( childCanonicalConfigPath ) ;
882- // falls through
891+ // falls through
892+ case ConfiguredProjectLoadKind . CreateReplayOptimized :
883893 case ConfiguredProjectLoadKind . FindOptimized :
884894 if ( childProject || loadKind !== ConfiguredProjectLoadKind . FindOptimized ) {
885895 const result = cb (
@@ -930,6 +940,12 @@ function updateProjectFoundUsingFind(
930940 // This project was found using "Find" instead of the actually specified kind of "Create" or "Reload",
931941 // We need to update or reload this existing project before calling callback
932942 switch ( kind ) {
943+ case ConfiguredProjectLoadKind . CreateReplayOptimized :
944+ case ConfiguredProjectLoadKind . CreateReplay :
945+ if ( useConfigFileExistenceInfoForOptimizedLoading ( project ) ) {
946+ configFileExistenceInfo = project . projectService . configFileExistenceInfoCache . get ( project . canonicalConfigFilePath ) ! ;
947+ }
948+ break ;
933949 case ConfiguredProjectLoadKind . CreateOptimized :
934950 configFileExistenceInfo = configFileExistenceInfoForOptimizedLoading ( project ) ;
935951 if ( configFileExistenceInfo ) break ;
@@ -1077,9 +1093,21 @@ function configFileExistenceInfoForOptimizedLoading(project: ConfiguredProject)
10771093 project . resolvedChildConfigs = undefined ;
10781094 project . updateReferences ( parsedCommandLine . projectReferences ) ;
10791095 // Composite can determine based on files themselves, no need to load project
1080- if ( parsedCommandLine . options . composite ) return configFileExistenceInfo ;
10811096 // If solution, no need to load it to determine if file belongs to it
1082- if ( isSolutionConfig ( parsedCommandLine ) ) return configFileExistenceInfo ;
1097+ if ( useConfigFileExistenceInfoForOptimizedLoading ( project ) ) return configFileExistenceInfo ;
1098+ }
1099+
1100+ function useConfigFileExistenceInfoForOptimizedLoading ( project : ConfiguredProject ) {
1101+ return ! ! project . parsedCommandLine &&
1102+ ( ! ! project . parsedCommandLine . options . composite ||
1103+ // If solution, no need to load it to determine if file belongs to it
1104+ ! ! isSolutionConfig ( project . parsedCommandLine ) ) ;
1105+ }
1106+
1107+ function configFileExistenceInfoForOptimizedReplay ( project : ConfiguredProject ) {
1108+ return useConfigFileExistenceInfoForOptimizedLoading ( project ) ?
1109+ project . projectService . configFileExistenceInfoCache . get ( project . canonicalConfigFilePath ) ! :
1110+ undefined ;
10831111}
10841112
10851113function fileOpenReason ( info : ScriptInfo ) {
@@ -2603,11 +2631,22 @@ export class ProjectService {
26032631
26042632 /** @internal */
26052633 findDefaultConfiguredProject ( info : ScriptInfo ) {
2634+ return this . findDefaultConfiguredProjectWorker (
2635+ info ,
2636+ ConfiguredProjectLoadKind . Find ,
2637+ ) ?. defaultProject ;
2638+ }
2639+
2640+ /** @internal */
2641+ findDefaultConfiguredProjectWorker (
2642+ info : ScriptInfo ,
2643+ kind : ConfiguredProjectLoadKind . Find | ConfiguredProjectLoadKind . CreateReplay ,
2644+ ) {
26062645 return info . isScriptOpen ( ) ?
26072646 this . tryFindDefaultConfiguredProjectForOpenScriptInfo (
26082647 info ,
2609- ConfiguredProjectLoadKind . Find ,
2610- ) ?. defaultProject :
2648+ kind ,
2649+ ) :
26112650 undefined ;
26122651 }
26132652
@@ -4360,8 +4399,13 @@ export class ProjectService {
43604399 switch ( kind ) {
43614400 case ConfiguredProjectLoadKind . FindOptimized :
43624401 case ConfiguredProjectLoadKind . Find :
4402+ case ConfiguredProjectLoadKind . CreateReplay :
43634403 if ( ! project ) return ;
43644404 break ;
4405+ case ConfiguredProjectLoadKind . CreateReplayOptimized :
4406+ if ( ! project ) return ;
4407+ configFileExistenceInfo = configFileExistenceInfoForOptimizedReplay ( project ) ;
4408+ break ;
43654409 case ConfiguredProjectLoadKind . CreateOptimized :
43664410 case ConfiguredProjectLoadKind . Create :
43674411 project ??= this . createConfiguredProject ( configFileName , reason ! ) ;
@@ -4414,7 +4458,7 @@ export class ProjectService {
44144458 /** Used with ConfiguredProjectLoadKind.Reload to check if this project was already reloaded */
44154459 reloadedProjects ?: ConfiguredProjectToAnyReloadKind ,
44164460 ) : DefaultConfiguredProjectResult | undefined {
4417- const configFileName = this . getConfigFileNameForFile ( info , kind === ConfiguredProjectLoadKind . Find ) ;
4461+ const configFileName = this . getConfigFileNameForFile ( info , kind <= ConfiguredProjectLoadKind . CreateReplay ) ;
44184462 // If no config file name, no result
44194463 if ( ! configFileName ) return ;
44204464
@@ -4508,6 +4552,7 @@ export class ProjectService {
45084552 tsconfigProject : tsconfigOfDefault ?? tsconfigOfPossiblyDefault ,
45094553 sentConfigDiag,
45104554 seenProjects,
4555+ seenConfigs,
45114556 } ;
45124557
45134558 function tryFindDefaultConfiguredProject ( result : FindCreateOrLoadConfiguredProjectResult ) : ConfiguredProject | undefined {
@@ -4569,7 +4614,12 @@ export class ProjectService {
45694614 allowDeferredClosed ,
45704615 info . fileName ,
45714616 reloadedProjects ,
4572- ) ! ;
4617+ ) ;
4618+ if ( ! result ) {
4619+ // Did no find existing project but thats ok, we will give information based on what we find
4620+ Debug . assert ( kind === ConfiguredProjectLoadKind . CreateReplay ) ;
4621+ return undefined ;
4622+ }
45734623 seenProjects . set ( result . project , optimizedKind ) ;
45744624 if ( result . sentConfigFileDiag ) sentConfigDiag . add ( result . project ) ;
45754625 return isDefaultProject ( result . project , tsconfigProject ) ;
@@ -4658,7 +4708,7 @@ export class ProjectService {
46584708 ) : DefaultConfiguredProjectResult | undefined ;
46594709 private tryFindDefaultConfiguredProjectAndLoadAncestorsForOpenScriptInfo (
46604710 info : ScriptInfo ,
4661- kind : ConguredProjectLoadFindCreateOrReload ,
4711+ kind : ConfiguredProjectLoadKind . Find | ConfiguredProjectLoadKind . Create | ConfiguredProjectLoadKind . Reload ,
46624712 reloadedProjects ?: ConfiguredProjectToAnyReloadKind ,
46634713 delayReloadedConfiguredProjects ?: Set < ConfiguredProject > ,
46644714 ) : DefaultConfiguredProjectResult | undefined {
0 commit comments