* 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)
| 495 | * taking exactly that many, else the first. |
| 496 | */ |
| 497 | function 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 |
no test coverage detected