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

Function nearest

src/resolution/pascal-scope.ts:2601–2616  ·  view source on GitHub ↗

The file whose path shares the longest directory prefix with `from`.

(files: string[], from: string)

Source from the content-addressed store, hash-verified

2599
2600/** The file whose path shares the longest directory prefix with `from`. */
2601function nearest(files: string[], from: string): string | null {
2602 if (files.length <= 1) return files[0] ?? null;
2603 const dirs = from.split('/');
2604 let best: string | null = null;
2605 let bestScore = -1;
2606 for (const f of files) {
2607 const parts = f.split('/');
2608 let score = 0;
2609 while (score < parts.length && score < dirs.length && parts[score] === dirs[score]) score++;
2610 if (score > bestScore) {
2611 best = f;
2612 bestScore = score;
2613 }
2614 }
2615 return best;
2616}
2617
2618// ---------------------------------------------------------------------------
2619// Declared types

Callers 4

scanInterfaceFunction · 0.85
unitsIncludedInUsesFunction · 0.85
includesOfFunction · 0.85
unitFileNamedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected