Skip to content

Commit 5fd6a6f

Browse files
authored
Revert of Search ancestor and its references for default projects microsoft#57196 (microsoft#59634)
1 parent aaa6c4e commit 5fd6a6f

File tree

121 files changed

+3861
-8235
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+3861
-8235
lines changed

src/server/editorServices.ts

Lines changed: 25 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import {
3131
DocumentRegistry,
3232
DocumentRegistryBucketKeyWithMode,
3333
emptyOptions,
34-
endsWith,
3534
ensureTrailingDirectorySeparator,
3635
equateStringsCaseInsensitive,
3736
equateStringsCaseSensitive,
@@ -645,37 +644,10 @@ export interface ProjectServiceOptions {
645644
*/
646645
export type ConfigFileName = NormalizedPath | false;
647646

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-
664647
/** 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);
679651
}
680652

681653
/** @internal */
@@ -690,7 +662,6 @@ export interface AncestorConfigFileInfo {
690662
/** path of open file so we can look at correct root */
691663
path: Path;
692664
configFileInfo: true;
693-
isForDefaultProject: boolean;
694665
}
695666
/** @internal */
696667
export type OpenScriptInfoOrClosedFileInfo = ScriptInfo | OriginalFileInfo;
@@ -739,8 +710,6 @@ function forEachAncestorProject<T>(
739710
allowDeferredClosed: boolean | undefined,
740711
/** Used with ConfiguredProjectLoadKind.Reload to check if this project was already reloaded */
741712
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,
744713
/** Used with ConfiguredProjectLoadKind.Reload to specify delay reload, and also a set of configured projects already marked for delay load */
745714
delayReloadedConfiguredProjects?: Set<ConfiguredProject>,
746715
): T | undefined {
@@ -750,10 +719,7 @@ function forEachAncestorProject<T>(
750719
if (
751720
!project.isInitialLoadPending() &&
752721
(
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 ||
757723
project.getCompilerOptions().disableSolutionSearching
758724
)
759725
) return;
@@ -763,7 +729,6 @@ function forEachAncestorProject<T>(
763729
fileName: project.getConfigFilePath(),
764730
path: info.path,
765731
configFileInfo: true,
766-
isForDefaultProject: !searchOnlyPotentialSolution,
767732
}, kind === ConfiguredProjectLoadKind.Find);
768733
if (!configFileName) return;
769734

@@ -773,9 +738,9 @@ function forEachAncestorProject<T>(
773738
kind,
774739
reason,
775740
allowDeferredClosed,
776-
!searchOnlyPotentialSolution ? info.fileName : undefined, // Config Diag event for project if its for default project
741+
/*triggerFile*/ undefined,
777742
reloadedProjects,
778-
searchOnlyPotentialSolution, // Delay load if we are searching for solution
743+
/*delayLoad*/ true,
779744
delayReloadedConfiguredProjects,
780745
);
781746
if (!ancestor) return;
@@ -1241,7 +1206,7 @@ export class ProjectService {
12411206
*/
12421207
readonly openFiles: Map<Path, NormalizedPath | undefined> = new Map<Path, NormalizedPath | undefined>();
12431208
/** 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>();
12451210
/** Set of open script infos that are root of inferred project */
12461211
private rootOfInferredProjects = new Set<ScriptInfo>();
12471212
/**
@@ -1280,7 +1245,7 @@ export class ProjectService {
12801245
* All the open script info that needs recalculation of the default project,
12811246
* this also caches config file info before config file change was detected to use it in case projects are not updated yet
12821247
*/
1283-
private pendingOpenFileProjectUpdates?: Map<Path, ConfigFileForOpenFile>;
1248+
private pendingOpenFileProjectUpdates?: Map<Path, ConfigFileName>;
12841249
/** @internal */
12851250
pendingEnsureProjectForOpenFiles = false;
12861251

@@ -2290,7 +2255,7 @@ export class ProjectService {
22902255
const configFileExistenceInfo = this.configFileExistenceInfoCache.get(canonicalConfigFilePath);
22912256

22922257
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)) {
22942259
// By default the info would get impacted by presence of config file since its in the detection path
22952260
// Only adding the info as a root to inferred project will need the existence to be watched by file watcher
22962261
if (configFileExistenceInfo) (configFileExistenceInfo.openFilesImpactedByConfigFile ??= new Set()).add(info.path);
@@ -2483,39 +2448,31 @@ export class ProjectService {
24832448

24842449
// If projectRootPath doesn't contain info.path, then do normal search for config file
24852450
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);
24942453
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);
24972456
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);
24992458
if (result) return tsconfigFileName;
2500-
}
25012459

2502-
if (searchJsconfig) {
25032460
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);
25052462
if (result) return jsconfigFileName;
2506-
}
25072463

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+
}
25132470
}
25142471

25152472
const parentPath = asNormalizedPath(getDirectoryPath(searchPath));
25162473
if (parentPath === searchPath) break;
25172474
searchPath = parentPath;
2518-
searchTsconfig = searchJsconfig = true;
2475+
searchInDirectory = true;
25192476
}
25202477
while (anySearchPathOk || isSearchPathInProjectRoot());
25212478

@@ -2550,24 +2507,8 @@ export class ProjectService {
25502507
configFileName: NormalizedPath | undefined,
25512508
) {
25522509
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);
25712512
}
25722513

25732514
/**
@@ -4293,8 +4234,7 @@ export class ProjectService {
42934234
function tryFindDefaultConfiguredProject(project: ConfiguredProject): ConfiguredProject | undefined {
42944235
return isDefaultProject(project) ?
42954236
defaultProject :
4296-
(tryFindDefaultConfiguredProjectFromReferences(project) ??
4297-
tryFindDefaultConfiguredProjectFromAncestor(project));
4237+
tryFindDefaultConfiguredProjectFromReferences(project);
42984238
}
42994239

43004240
function isDefaultProject(project: ConfiguredProject): ConfiguredProject | undefined {
@@ -4324,19 +4264,6 @@ export class ProjectService {
43244264
reloadedProjects,
43254265
);
43264266
}
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-
}
43404267
}
43414268

43424269
/**
@@ -4381,7 +4308,6 @@ export class ProjectService {
43814308
`Creating project possibly referencing default composite project ${defaultProject.getProjectName()} of open file ${info.fileName}`,
43824309
allowDeferredClosed,
43834310
reloadedProjects,
4384-
/*searchOnlyPotentialSolution*/ true,
43854311
delayReloadedConfiguredProjects,
43864312
);
43874313
}

tests/baselines/reference/tsserver/configuredProjects/Open-ref-of-configured-project-when-open-file-gets-added-to-the-project-as-part-of-configured-file-update-buts-its-open-file-references-are-all-closed-when-the-update-happens.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ Info seq [hh:mm:ss:mss] request:
233233
"type": "request"
234234
}
235235
Info seq [hh:mm:ss:mss] getConfigFileNameForFile:: File: /a/b/src/file2.ts ProjectRootPath: undefined:: Result: /a/b/tsconfig.json
236-
Info seq [hh:mm:ss:mss] getConfigFileNameForFile:: File: /a/b/tsconfig.json ProjectRootPath: undefined:: Result: undefined
237236
Info seq [hh:mm:ss:mss] event:
238237
{
239238
"seq": 0,

tests/baselines/reference/tsserver/configuredProjects/Open-ref-of-configured-project-when-open-file-gets-added-to-the-project-as-part-of-configured-file-update.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ Info seq [hh:mm:ss:mss] request:
233233
"type": "request"
234234
}
235235
Info seq [hh:mm:ss:mss] getConfigFileNameForFile:: File: /a/b/src/file2.ts ProjectRootPath: undefined:: Result: /a/b/tsconfig.json
236-
Info seq [hh:mm:ss:mss] getConfigFileNameForFile:: File: /a/b/tsconfig.json ProjectRootPath: undefined:: Result: undefined
237236
Info seq [hh:mm:ss:mss] event:
238237
{
239238
"seq": 0,

tests/baselines/reference/tsserver/configuredProjects/add-and-then-remove-a-config-file-in-a-folder-with-loose-files.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,6 @@ Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/commonFile
354354
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
355355
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/commonFile2.ts ProjectRootPath: undefined
356356
Info seq [hh:mm:ss:mss] Projects: /dev/null/inferredProject2*
357-
Info seq [hh:mm:ss:mss] getConfigFileNameForFile:: File: /user/username/projects/myproject/tsconfig.json ProjectRootPath: undefined:: Result: undefined
358357
Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /dev/null/inferredProject1*
359358
Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /dev/null/inferredProject1* projectStateVersion: 2 projectProgramVersion: 1 structureChanged: true structureIsReused:: Not Elapsed:: *ms
360359
Info seq [hh:mm:ss:mss] Project '/dev/null/inferredProject1*' (Inferred)
@@ -646,7 +645,6 @@ Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/commonFile
646645
Info seq [hh:mm:ss:mss] Projects: /dev/null/inferredProject1*,/user/username/projects/myproject/tsconfig.json
647646
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/commonFile2.ts ProjectRootPath: undefined
648647
Info seq [hh:mm:ss:mss] Projects: /dev/null/inferredProject2*
649-
Info seq [hh:mm:ss:mss] getConfigFileNameForFile:: File: /user/username/projects/myproject/tsconfig.json ProjectRootPath: undefined:: Result: undefined
650648
Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /dev/null/inferredProject1*
651649
Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /dev/null/inferredProject1* projectStateVersion: 4 projectProgramVersion: 3 structureChanged: true structureIsReused:: Not Elapsed:: *ms
652650
Info seq [hh:mm:ss:mss] Project '/dev/null/inferredProject1*' (Inferred)
@@ -1596,7 +1594,6 @@ Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/commonFile
15961594
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
15971595
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/commonFile2.ts ProjectRootPath: undefined
15981596
Info seq [hh:mm:ss:mss] Projects: /dev/null/inferredProject4*
1599-
Info seq [hh:mm:ss:mss] getConfigFileNameForFile:: File: /user/username/projects/myproject/tsconfig.json ProjectRootPath: undefined:: Result: undefined
16001597
Info seq [hh:mm:ss:mss] After ensureProjectForOpenFiles:
16011598
Info seq [hh:mm:ss:mss] Project '/user/username/projects/myproject/tsconfig.json' (Configured)
16021599
Info seq [hh:mm:ss:mss] Files (2)

0 commit comments

Comments
 (0)