* One type's method among `candidates`, or null when they belong to different * types. Of a type's overloads, the one declared to take a `Request` — what * Vapor calls a handler with — else the earliest.
(candidates: Node[], ownerOf: (n: Node) => string, context: ResolutionContext)
| 477 | * Vapor calls a handler with — else the earliest. |
| 478 | */ |
| 479 | function oneOwnersMethod(candidates: Node[], ownerOf: (n: Node) => string, context: ResolutionContext): string | null { |
| 480 | if (candidates.length === 0) return null; |
| 481 | if (new Set(candidates.map(ownerOf)).size > 1) return null; |
| 482 | const earliest = (nodes: Node[]) => nodes.reduce((a, b) => (a.startLine <= b.startLine ? a : b)).id; |
| 483 | if (candidates.length === 1) return candidates[0]!.id; |
| 484 | const takesRequest = candidates.filter((n) => { |
| 485 | const lines = context.readFile(n.filePath)?.split(/\r?\n/) ?? []; |
| 486 | const head = lines.slice(n.startLine - 1, Math.min(n.endLine, n.startLine + 2)).join(' '); |
| 487 | return /\(\s*(?:\w+\s+)?\w+\s*:\s*Request\b/.test(head); |
| 488 | }); |
| 489 | return earliest(takesRequest.length > 0 ? takesRequest : candidates); |
| 490 | } |
| 491 | |
| 492 | function resolveVaporHandler(typePath: string | null, method: string, ref: UnresolvedRef, context: ResolutionContext): string | null { |
| 493 | const callables = context |
no test coverage detected