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

Function oneOwnersMethod

src/resolution/frameworks/swift.ts:479–490  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

477 * Vapor calls a handler with — else the earliest.
478 */
479function 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
492function resolveVaporHandler(typePath: string | null, method: string, ref: UnresolvedRef, context: ResolutionContext): string | null {
493 const callables = context

Callers 1

resolveVaporHandlerFunction · 0.85

Calls 4

earliestFunction · 0.85
mapMethod · 0.80
readFileMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected