MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / rustCrateRootDir

Function rustCrateRootDir

src/resolution/import-resolver.ts:1845–1859  ·  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

1843
1844/** The crate-root directory (holds `lib.rs`/`main.rs`), walking up from a file. */
1845function rustCrateRootDir(fromFileAbs: string, context: ResolutionContext): string | null {
1846 const projectRoot = context.getProjectRoot();
1847 const toRel = (p: string) => path.relative(projectRoot, p).replace(/\\/g, '/');
1848 let dir = path.dirname(fromFileAbs);
1849 for (let i = 0; i < 64; i++) {
1850 if (context.fileExists(toRel(path.join(dir, 'lib.rs'))) ||
1851 context.fileExists(toRel(path.join(dir, 'main.rs')))) {
1852 return dir;
1853 }
1854 const parent = path.dirname(dir);
1855 if (parent === dir) return null;
1856 dir = parent;
1857 }
1858 return null;
1859}
1860
1861/** Directory under which the current file's module declares its SUBMODULES. */
1862function rustSelfModuleDir(fromFileAbs: string): string {

Callers 1

resolveRustModuleFileFunction · 0.85

Calls 4

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

Tested by

no test coverage detected