@@ -31,7 +31,6 @@ import {
31
31
DocumentRegistry ,
32
32
DocumentRegistryBucketKeyWithMode ,
33
33
emptyOptions ,
34
- endsWith ,
35
34
ensureTrailingDirectorySeparator ,
36
35
equateStringsCaseInsensitive ,
37
36
equateStringsCaseSensitive ,
@@ -645,37 +644,10 @@ export interface ProjectServiceOptions {
645
644
*/
646
645
export type ConfigFileName = NormalizedPath | false ;
647
646
648
- /**
649
- * Stores cached config file name for info as well as ancestor so is a map
650
- * Key is false for Open ScriptInfo
651
- * Key is NormalizedPath for Config file name
652
- * @internal
653
- */
654
- export type ConfigFileMapForOpenFile = Map < ConfigFileName , ConfigFileName > ;
655
-
656
- /**
657
- * The cache for open script info will have
658
- * ConfigFileName or false if ancestors are not looked up
659
- * Map if ancestors are looked up
660
- * @internal
661
- */
662
- export type ConfigFileForOpenFile = ConfigFileName | ConfigFileMapForOpenFile ;
663
-
664
647
/** Gets cached value of config file name based on open script info or ancestor script info */
665
- function getConfigFileNameFromCache ( info : OpenScriptInfoOrClosedOrConfigFileInfo , cache : Map < Path , ConfigFileForOpenFile > | undefined ) : ConfigFileName | undefined {
666
- if ( ! cache ) return undefined ;
667
- const configFileForOpenFile = cache . get ( info . path ) ;
668
- if ( configFileForOpenFile === undefined ) return undefined ;
669
- if ( ! isAncestorConfigFileInfo ( info ) ) {
670
- return isString ( configFileForOpenFile ) || ! configFileForOpenFile ?
671
- configFileForOpenFile : // direct result
672
- configFileForOpenFile . get ( /*key*/ false ) ; // Its a map, use false as the key for the info's config file name
673
- }
674
- else {
675
- return configFileForOpenFile && ! isString ( configFileForOpenFile ) ? // Map with fileName as key
676
- configFileForOpenFile . get ( info . fileName ) :
677
- undefined ; // No result for the config file name
678
- }
648
+ function getConfigFileNameFromCache ( info : OpenScriptInfoOrClosedOrConfigFileInfo , cache : Map < Path , ConfigFileName > | undefined ) : ConfigFileName | undefined {
649
+ if ( ! cache || isAncestorConfigFileInfo ( info ) ) return undefined ;
650
+ return cache . get ( info . path ) ;
679
651
}
680
652
681
653
/** @internal */
@@ -690,7 +662,6 @@ export interface AncestorConfigFileInfo {
690
662
/** path of open file so we can look at correct root */
691
663
path : Path ;
692
664
configFileInfo : true ;
693
- isForDefaultProject : boolean ;
694
665
}
695
666
/** @internal */
696
667
export type OpenScriptInfoOrClosedFileInfo = ScriptInfo | OriginalFileInfo ;
@@ -739,8 +710,6 @@ function forEachAncestorProject<T>(
739
710
allowDeferredClosed : boolean | undefined ,
740
711
/** Used with ConfiguredProjectLoadKind.Reload to check if this project was already reloaded */
741
712
reloadedProjects : Set < ConfiguredProject > | undefined ,
742
- /** true means we are looking for solution, so we can stop if found project is not composite to go into parent solution */
743
- searchOnlyPotentialSolution : boolean ,
744
713
/** Used with ConfiguredProjectLoadKind.Reload to specify delay reload, and also a set of configured projects already marked for delay load */
745
714
delayReloadedConfiguredProjects ?: Set < ConfiguredProject > ,
746
715
) : T | undefined {
@@ -750,10 +719,7 @@ function forEachAncestorProject<T>(
750
719
if (
751
720
! project . isInitialLoadPending ( ) &&
752
721
(
753
- ( searchOnlyPotentialSolution && ! project . getCompilerOptions ( ) . composite ) ||
754
- // Currently disableSolutionSearching is shared for finding solution/project when
755
- // - loading solution for find all references
756
- // - trying to find default project
722
+ ! project . getCompilerOptions ( ) . composite ||
757
723
project . getCompilerOptions ( ) . disableSolutionSearching
758
724
)
759
725
) return ;
@@ -763,7 +729,6 @@ function forEachAncestorProject<T>(
763
729
fileName : project . getConfigFilePath ( ) ,
764
730
path : info . path ,
765
731
configFileInfo : true ,
766
- isForDefaultProject : ! searchOnlyPotentialSolution ,
767
732
} , kind === ConfiguredProjectLoadKind . Find ) ;
768
733
if ( ! configFileName ) return ;
769
734
@@ -773,9 +738,9 @@ function forEachAncestorProject<T>(
773
738
kind ,
774
739
reason ,
775
740
allowDeferredClosed ,
776
- ! searchOnlyPotentialSolution ? info . fileName : undefined , // Config Diag event for project if its for default project
741
+ /*triggerFile*/ undefined ,
777
742
reloadedProjects ,
778
- searchOnlyPotentialSolution , // Delay load if we are searching for solution
743
+ /*delayLoad*/ true ,
779
744
delayReloadedConfiguredProjects ,
780
745
) ;
781
746
if ( ! ancestor ) return ;
@@ -1241,7 +1206,7 @@ export class ProjectService {
1241
1206
*/
1242
1207
readonly openFiles : Map < Path , NormalizedPath | undefined > = new Map < Path , NormalizedPath | undefined > ( ) ;
1243
1208
/** Config files looked up and cached config files for open script info */
1244
- private readonly configFileForOpenFiles = new Map < Path , ConfigFileForOpenFile > ( ) ;
1209
+ private readonly configFileForOpenFiles = new Map < Path , ConfigFileName > ( ) ;
1245
1210
/** Set of open script infos that are root of inferred project */
1246
1211
private rootOfInferredProjects = new Set < ScriptInfo > ( ) ;
1247
1212
/**
@@ -1280,7 +1245,7 @@ export class ProjectService {
1280
1245
* All the open script info that needs recalculation of the default project,
1281
1246
* this also caches config file info before config file change was detected to use it in case projects are not updated yet
1282
1247
*/
1283
- private pendingOpenFileProjectUpdates ?: Map < Path , ConfigFileForOpenFile > ;
1248
+ private pendingOpenFileProjectUpdates ?: Map < Path , ConfigFileName > ;
1284
1249
/** @internal */
1285
1250
pendingEnsureProjectForOpenFiles = false ;
1286
1251
@@ -2290,7 +2255,7 @@ export class ProjectService {
2290
2255
const configFileExistenceInfo = this . configFileExistenceInfoCache . get ( canonicalConfigFilePath ) ;
2291
2256
2292
2257
let openFilesImpactedByConfigFile : Set < Path > | undefined ;
2293
- if ( this . openFiles . has ( info . path ) && ( ! isAncestorConfigFileInfo ( info ) || info . isForDefaultProject ) ) {
2258
+ if ( this . openFiles . has ( info . path ) && ! isAncestorConfigFileInfo ( info ) ) {
2294
2259
// By default the info would get impacted by presence of config file since its in the detection path
2295
2260
// Only adding the info as a root to inferred project will need the existence to be watched by file watcher
2296
2261
if ( configFileExistenceInfo ) ( configFileExistenceInfo . openFilesImpactedByConfigFile ??= new Set ( ) ) . add ( info . path ) ;
@@ -2483,39 +2448,31 @@ export class ProjectService {
2483
2448
2484
2449
// If projectRootPath doesn't contain info.path, then do normal search for config file
2485
2450
const anySearchPathOk = ! projectRootPath || ! isSearchPathInProjectRoot ( ) ;
2486
-
2487
- let searchTsconfig = true ;
2488
- let searchJsconfig = true ;
2489
- if ( isAncestorConfigFileInfo ( info ) ) {
2490
- // For ancestor of config file always ignore itself
2491
- if ( endsWith ( info . fileName , "tsconfig.json" ) ) searchTsconfig = false ;
2492
- else searchTsconfig = searchJsconfig = false ;
2493
- }
2451
+ // For ancestor of config file always ignore its own directory since its going to result in itself
2452
+ let searchInDirectory = ! isAncestorConfigFileInfo ( info ) ;
2494
2453
do {
2495
- const canonicalSearchPath = normalizedPathToPath ( searchPath , this . currentDirectory , this . toCanonicalFileName ) ;
2496
- if ( searchTsconfig ) {
2454
+ if ( searchInDirectory ) {
2455
+ const canonicalSearchPath = normalizedPathToPath ( searchPath , this . currentDirectory , this . toCanonicalFileName ) ;
2497
2456
const tsconfigFileName = asNormalizedPath ( combinePaths ( searchPath , "tsconfig.json" ) ) ;
2498
- const result = action ( combinePaths ( canonicalSearchPath , "tsconfig.json" ) as NormalizedPath , tsconfigFileName ) ;
2457
+ let result = action ( combinePaths ( canonicalSearchPath , "tsconfig.json" ) as NormalizedPath , tsconfigFileName ) ;
2499
2458
if ( result ) return tsconfigFileName ;
2500
- }
2501
2459
2502
- if ( searchJsconfig ) {
2503
2460
const jsconfigFileName = asNormalizedPath ( combinePaths ( searchPath , "jsconfig.json" ) ) ;
2504
- const result = action ( combinePaths ( canonicalSearchPath , "jsconfig.json" ) as NormalizedPath , jsconfigFileName ) ;
2461
+ result = action ( combinePaths ( canonicalSearchPath , "jsconfig.json" ) as NormalizedPath , jsconfigFileName ) ;
2505
2462
if ( result ) return jsconfigFileName ;
2506
- }
2507
2463
2508
- // If we started within node_modules, don't look outside node_modules.
2509
- // Otherwise, we might pick up a very large project and pull in the world,
2510
- // causing an editor delay.
2511
- if ( isNodeModulesDirectory ( canonicalSearchPath ) ) {
2512
- break ;
2464
+ // If we started within node_modules, don't look outside node_modules.
2465
+ // Otherwise, we might pick up a very large project and pull in the world,
2466
+ // causing an editor delay.
2467
+ if ( isNodeModulesDirectory ( canonicalSearchPath ) ) {
2468
+ break ;
2469
+ }
2513
2470
}
2514
2471
2515
2472
const parentPath = asNormalizedPath ( getDirectoryPath ( searchPath ) ) ;
2516
2473
if ( parentPath === searchPath ) break ;
2517
2474
searchPath = parentPath ;
2518
- searchTsconfig = searchJsconfig = true ;
2475
+ searchInDirectory = true ;
2519
2476
}
2520
2477
while ( anySearchPathOk || isSearchPathInProjectRoot ( ) ) ;
2521
2478
@@ -2550,24 +2507,8 @@ export class ProjectService {
2550
2507
configFileName : NormalizedPath | undefined ,
2551
2508
) {
2552
2509
if ( ! this . openFiles . has ( info . path ) ) return ; // Dont cache for closed script infos
2553
- const config = configFileName || false ;
2554
- if ( ! isAncestorConfigFileInfo ( info ) ) {
2555
- // Set value for open script info
2556
- this . configFileForOpenFiles . set ( info . path , config ) ;
2557
- }
2558
- else {
2559
- // Need to set value for ancestor in ConfigFileMapForOpenFile
2560
- let configFileForOpenFile = this . configFileForOpenFiles . get ( info . path ) ! ;
2561
- if ( ! configFileForOpenFile || isString ( configFileForOpenFile ) ) {
2562
- // We have value for open script info in cache, make a map with that as false key and set new vlaue
2563
- this . configFileForOpenFiles . set (
2564
- info . path ,
2565
- configFileForOpenFile = new Map ( ) . set ( false , configFileForOpenFile ) ,
2566
- ) ;
2567
- }
2568
- // Set value of for ancestor in the map
2569
- configFileForOpenFile . set ( info . fileName , config ) ;
2570
- }
2510
+ if ( isAncestorConfigFileInfo ( info ) ) return ; // Dont cache for ancestors
2511
+ this . configFileForOpenFiles . set ( info . path , configFileName || false ) ;
2571
2512
}
2572
2513
2573
2514
/**
@@ -4293,8 +4234,7 @@ export class ProjectService {
4293
4234
function tryFindDefaultConfiguredProject ( project : ConfiguredProject ) : ConfiguredProject | undefined {
4294
4235
return isDefaultProject ( project ) ?
4295
4236
defaultProject :
4296
- ( tryFindDefaultConfiguredProjectFromReferences ( project ) ??
4297
- tryFindDefaultConfiguredProjectFromAncestor ( project ) ) ;
4237
+ tryFindDefaultConfiguredProjectFromReferences ( project ) ;
4298
4238
}
4299
4239
4300
4240
function isDefaultProject ( project : ConfiguredProject ) : ConfiguredProject | undefined {
@@ -4324,19 +4264,6 @@ export class ProjectService {
4324
4264
reloadedProjects ,
4325
4265
) ;
4326
4266
}
4327
-
4328
- function tryFindDefaultConfiguredProjectFromAncestor ( project : ConfiguredProject ) {
4329
- return forEachAncestorProject ( // If not in referenced projects, try ancestors and its references
4330
- info ,
4331
- project ,
4332
- tryFindDefaultConfiguredProject ,
4333
- kind ,
4334
- `Creating possible configured project for ${ info . fileName } to open` ,
4335
- allowDeferredClosed ,
4336
- reloadedProjects ,
4337
- /*searchOnlyPotentialSolution*/ false ,
4338
- ) ;
4339
- }
4340
4267
}
4341
4268
4342
4269
/**
@@ -4381,7 +4308,6 @@ export class ProjectService {
4381
4308
`Creating project possibly referencing default composite project ${ defaultProject . getProjectName ( ) } of open file ${ info . fileName } ` ,
4382
4309
allowDeferredClosed ,
4383
4310
reloadedProjects ,
4384
- /*searchOnlyPotentialSolution*/ true ,
4385
4311
delayReloadedConfiguredProjects ,
4386
4312
) ;
4387
4313
}
0 commit comments