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

Function unitFileNamed

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

The file of the unit a name names, nearest to `fromFile` when several units share it.

(lower: string, fromFile: string, context: ResolutionContext)

Source from the content-addressed store, hash-verified

2505
2506/** The file of the unit a name names, nearest to `fromFile` when several units share it. */
2507function unitFileNamed(lower: string, fromFile: string, context: ResolutionContext): string | null {
2508 const m = memos(context);
2509 const key = `${fromFile}|${lower}`;
2510 if (m.unitFiles.has(key)) return m.unitFiles.get(key)!;
2511 if (!m.unitsByName) {
2512 const units = new Map<string, string[]>();
2513 const add = (name: string, file: string): void => {
2514 const files = units.get(name);
2515 if (files) files.push(file);
2516 else units.set(name, [file]);
2517 };
2518 const headed = new Set<string>();
2519 for (const n of context.getNodesByKind('module')) {
2520 if (n.language !== 'pascal') continue;
2521 add(n.name.toLowerCase(), n.filePath);
2522 headed.add(n.filePath);
2523 }
2524 // A unit's file is named after it, which Delphi enforces: one whose
2525 // `unit` header the parser lost to an error is the unit its file names.
2526 for (const file of context.getAllFiles()) {
2527 if (headed.has(file) || !/\.pas$/i.test(file)) continue;
2528 add(file.slice(file.lastIndexOf('/') + 1, -'.pas'.length).toLowerCase(), file);
2529 }
2530 m.unitsByName = units;
2531 }
2532 const file = nearest(m.unitsByName.get(lower) ?? [], fromFile);
2533 m.unitFiles.set(key, file);
2534 return file;
2535}
2536
2537/** A class (or record or interface) a type name names, seen from `fromFile`. */
2538function classNamed(typeName: string, fromFile: string, context: ResolutionContext): Node | null {

Callers 4

memberAtPathFunction · 0.85
headOfFunction · 0.85
typeOfLinksFunction · 0.85
addFunction · 0.85

Calls 9

memosFunction · 0.85
nearestFunction · 0.85
hasMethod · 0.80
addFunction · 0.70
getMethod · 0.65
getNodesByKindMethod · 0.65
getAllFilesMethod · 0.65
addMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected