MCPcopy
hub / github.com/colbymchenry/codegraph / rustCrateRootDir

Function rustCrateRootDir

src/resolution/import-resolver.ts:1597–1611  ·  view source on GitHub ↗

The crate-root directory (holds `lib.rs`/`main.rs`), walking up from a file.

(fromFileAbs: string, context: ResolutionContext)

Source from the content-addressed store, hash-verified

1595
1596/** The crate-root directory (holds `lib.rs`/`main.rs`), walking up from a file. */
1597function rustCrateRootDir(fromFileAbs: string, context: ResolutionContext): string | null {
1598 const projectRoot = context.getProjectRoot();
1599 const toRel = (p: string) => path.relative(projectRoot, p).replace(/\\/g, '/');
1600 let dir = path.dirname(fromFileAbs);
1601 for (let i = 0; i < 64; i++) {
1602 if (context.fileExists(toRel(path.join(dir, 'lib.rs'))) ||
1603 context.fileExists(toRel(path.join(dir, 'main.rs')))) {
1604 return dir;
1605 }
1606 const parent = path.dirname(dir);
1607 if (parent === dir) return null;
1608 dir = parent;
1609 }
1610 return null;
1611}
1612
1613/** Directory under which the current file's module declares its SUBMODULES. */
1614function rustSelfModuleDir(fromFileAbs: string): string {

Callers 1

resolveRustModuleFileFunction · 0.85

Calls 4

toRelFunction · 0.85
fileExistsMethod · 0.80
joinMethod · 0.80
getProjectRootMethod · 0.65

Tested by

no test coverage detected