Skip to content

Don't recurse when the answer doesn't change to 'true', just continue traversal #39934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/server/editorServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3775,24 +3775,28 @@ namespace ts.server {
getPackageJsonsVisibleToFile(fileName: string, rootDir?: string): readonly PackageJsonInfo[] {
const packageJsonCache = this.packageJsonCache;
const watchPackageJsonFile = this.watchPackageJsonFile.bind(this);
const toPath = this.toPath.bind(this);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was actually turning into any.

const rootPath = rootDir && toPath(rootDir);
const filePath = toPath(fileName);
const rootPath = rootDir && this.toPath(rootDir);
const filePath = this.toPath(fileName);
const result: PackageJsonInfo[] = [];
forEachAncestorDirectory(getDirectoryPath(filePath), function processDirectory(directory): boolean | undefined {
forEachAncestorDirectory(getDirectoryPath(filePath), directory => {
switch (packageJsonCache.directoryHasPackageJson(directory)) {
// Sync and check same directory again
case Ternary.Maybe:
// Sync and check same directory again
packageJsonCache.searchDirectoryAndAncestors(directory);
return processDirectory(directory);
// Check package.json
const newResult = packageJsonCache.directoryHasPackageJson(directory);
if (newResult !== Ternary.True) {
Debug.assertEqual(newResult, Ternary.False);
break;
}
// fall through
case Ternary.True:
// Check the package.json
const packageJsonFileName = combinePaths(directory, "package.json");
watchPackageJsonFile(packageJsonFileName);
const info = packageJsonCache.getInDirectory(directory);
if (info) result.push(info);
}
if (rootPath && rootPath === toPath(directory)) {
if (rootPath && rootPath === this.toPath(directory)) {
return true;
}
});
Expand Down