MCPcopy Create free account
hub / github.com/Dart-Code/Dart-Code / findRootContaining

Function findRootContaining

src/extension/sdk/utils.ts:759–780  ·  view source on GitHub ↗
(folder: string, childName: string, expect: "FILE" | "DIRECTORY" | "ANY")

Source from the content-addressed store, hash-verified

757}
758
759function findRootContaining(folder: string, childName: string, expect: "FILE" | "DIRECTORY" | "ANY"): string | undefined {
760 if (folder) {
761 // Walk up the directories from the workspace root, and see if there
762 // exists a directory which has `childName` file/directory as a child.
763 let child = folder;
764 while (child) {
765 try {
766 const fullPath = path.join(child, childName);
767 if (expect === "ANY" || (expect === "FILE" ? existsAndIsFileSync(fullPath) : existsAndIsDirectorySync(fullPath)))
768 return child;
769 } catch { }
770
771 const parentDir = path.dirname(child);
772 if (child === parentDir)
773 break;
774
775 child = parentDir;
776 }
777 }
778
779 return undefined;
780}
781
782enum GitOperationResult { success, error, cancelled };

Callers 3

findFuchsiaRootFunction · 0.85
findBazelWorkspaceRootFunction · 0.85
findGitRootFunction · 0.85

Calls 2

existsAndIsFileSyncFunction · 0.90
existsAndIsDirectorySyncFunction · 0.90

Tested by

no test coverage detected