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

Function pascalOverloadFor

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

* Of the overloads of the routine a call reached — the routines of its * qualified name and kind in its file — one the call's argument count fits, * when the reached one does not fit it (#3453). The name strategies choose * among overloads by where they are, and a routine is where its body is: *

(result: ResolvedRef, ref: UnresolvedRef, context: ResolutionContext)

Source from the content-addressed store, hash-verified

495 * taking exactly that many, else the first.
496 */
497function pascalOverloadFor(result: ResolvedRef, ref: UnresolvedRef, context: ResolutionContext): ResolvedRef {
498 const target = context.getNodeById?.(result.targetNodeId);
499 if (!target || target.language !== 'pascal' || (target.kind !== 'method' && target.kind !== 'function')) return result;
500 const overloads = context.getNodesByQualifiedName(target.qualifiedName).filter((n) =>
501 n.id !== target.id && n.kind === target.kind && n.language === 'pascal' && n.filePath === target.filePath);
502 if (overloads.length === 0) return result;
503 const count = pascalCallArgumentCount(ref, context);
504 if (count === null) return result;
505 const range = (n: Node): [number, number] | null => pascalParameterRange(n.signature);
506 const fits = (n: Node): boolean => {
507 const r = range(n);
508 return r !== null && count >= r[0] && count <= r[1];
509 };
510 if (fits(target)) return result;
511 const fitting = overloads.filter(fits);
512 if (fitting.length === 0) return result;
513 const choice = fitting.find((n) => range(n)![1] === count) ?? fitting[0]!;
514 context.rememberNode?.(choice);
515 return { ...result, targetNodeId: choice.id };
516}
517
518/**
519 * How many arguments a Pascal call passes: the list in parentheses after the

Callers 2

gatePascalCallFunction · 0.85
matchPascalHelperCallFunction · 0.85

Calls 6

pascalCallArgumentCountFunction · 0.85
rangeFunction · 0.85
rememberNodeMethod · 0.80
fitsFunction · 0.70
getNodeByIdMethod · 0.65

Tested by

no test coverage detected