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

Function unitFileNamed

src/resolution/pascal-scope.ts:971–999  ·  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

969
970/** The file of the unit a name names, nearest to `fromFile` when several units share it. */
971function unitFileNamed(lower: string, fromFile: string, context: ResolutionContext): string | null {
972 const m = memos(context);
973 const key = `${fromFile}|${lower}`;
974 if (m.unitFiles.has(key)) return m.unitFiles.get(key)!;
975 if (!m.unitsByName) {
976 const units = new Map<string, string[]>();
977 const add = (name: string, file: string): void => {
978 const files = units.get(name);
979 if (files) files.push(file);
980 else units.set(name, [file]);
981 };
982 const headed = new Set<string>();
983 for (const n of context.getNodesByKind('module')) {
984 if (n.language !== 'pascal') continue;
985 add(n.name.toLowerCase(), n.filePath);
986 headed.add(n.filePath);
987 }
988 // A unit's file is named after it, which Delphi enforces: one whose
989 // `unit` header the parser lost to an error is the unit its file names.
990 for (const file of context.getAllFiles()) {
991 if (headed.has(file) || !/\.pas$/i.test(file)) continue;
992 add(file.slice(file.lastIndexOf('/') + 1, -'.pas'.length).toLowerCase(), file);
993 }
994 m.unitsByName = units;
995 }
996 const file = nearest(m.unitsByName.get(lower) ?? [], fromFile);
997 m.unitFiles.set(key, file);
998 return file;
999}
1000
1001/** A class (or record or interface) a type name names, seen from `fromFile`. */
1002function classNamed(typeName: string, fromFile: string, context: ResolutionContext): Node | null {

Callers 3

memberAtPathFunction · 0.85
headOfFunction · 0.85
usedUnitFilesFunction · 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