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

Function matchPascalHelperCall

src/resolution/pascal-scope.ts:2076–2112  ·  view source on GitHub ↗
(ref: UnresolvedRef, context: ResolutionContext)

Source from the content-addressed store, hash-verified

2074 * method its type doesn't reach.
2075 */
2076export function matchPascalHelperCall(ref: UnresolvedRef, context: ResolutionContext): ResolvedRef | undefined {
2077 if (ref.language !== 'pascal' || ref.referenceKind !== 'calls') return undefined;
2078 const dot = ref.referenceName.lastIndexOf('.');
2079 if (dot <= 0) return undefined;
2080 const method = ref.referenceName.slice(dot + 1).toLowerCase();
2081 // Most names no helper declares: settled before the receiver is read.
2082 if (!helperMemberNames(context).has(method)) return undefined;
2083 const links = subjectLinks(ref.referenceName.slice(0, dot));
2084 if (!links) return undefined;
2085 const cls = classOfCall(ref, context);
2086 // The receiver's first name may be a member of a `with` subject around the call.
2087 const statements = withStatementsAt(ref, context);
2088 const subjects: Subject[] = [];
2089 for (const statement of statements) {
2090 for (let k = statement.subjects.length - 1; k >= 0; k--) subjects.push({ statement, k });
2091 }
2092 const outer = (lower: string): Node | null => {
2093 for (let p = 0; p < subjects.length; p++) {
2094 const type = withSubjectType(subjects, p, cls, ref, context);
2095 const member = type && memberOfValue(type, lower, ref.filePath!, context);
2096 if (member) return member;
2097 }
2098 return null;
2099 };
2100 const type = typeOfLinks(links, cls, ref, context, outer);
2101 if (!type) return undefined;
2102 // A type a lone name gives is one the file sees, not the project namesake
2103 // of an outside type (swagdoc's `System.JSON` `TJSONObject`, which
2104 // JsonDataObjects' `TJsonObject` is not; see visibleClassNamed).
2105 if (links.length === 1 && !(ownUnitFiles(ref.filePath!, context).includes(type.filePath) ||
2106 usedUnitFiles(ref.filePath!, context).includes(type.filePath))) return undefined;
2107 const reached = memberOfValue(type, method, ref.filePath!, context);
2108 if (!reached || !isRoutine(reached)) return undefined;
2109 const member = overloadByArity(reached, ref, context);
2110 context.rememberNode?.(member);
2111 return pascalOverloadFor({ original: ref, targetNodeId: member.id, confidence: 0.9, resolvedBy: 'instance-method' }, ref, context);
2112}
2113
2114/** The names of the routines the project's helpers declare, lowercased, whatever type each helps. */
2115function helperMemberNames(context: ResolutionContext): Set<string> {

Callers 1

resolveOneInnerMethod · 0.90

Calls 14

helperMemberNamesFunction · 0.85
subjectLinksFunction · 0.85
classOfCallFunction · 0.85
withStatementsAtFunction · 0.85
typeOfLinksFunction · 0.85
ownUnitFilesFunction · 0.85
usedUnitFilesFunction · 0.85
memberOfValueFunction · 0.85
isRoutineFunction · 0.85
overloadByArityFunction · 0.85
pascalOverloadForFunction · 0.85
hasMethod · 0.80

Tested by

no test coverage detected