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

Function implementationOf

src/resolution/python-overloads.ts:57–69  ·  view source on GitHub ↗

The implementation a stub stands for: the first `def` of its scope and name below it that is no stub.

(def: Node, context: ResolutionContext)

Source from the content-addressed store, hash-verified

55
56/** The implementation a stub stands for: the first `def` of its scope and name below it that is no stub. */
57function implementationOf(def: Node, context: ResolutionContext): string | null {
58 if (def.language !== 'python' || (def.kind !== 'function' && def.kind !== 'method')) return null;
59 const named = context.getNodesInFileNamed?.(def.filePath, def.name) ??
60 context.getNodesInFile(def.filePath).filter((n) => n.name === def.name);
61 const scope = named.filter((n) => n.kind === def.kind && n.qualifiedName === def.qualifiedName);
62 // The one def of its name in its scope: the common case, decided without reading the file.
63 if (scope.length < 2) return null;
64 const overload = overloadSpellings(def.filePath, context);
65 const lines = context.getFileLines?.(def.filePath) ?? context.readFile(def.filePath)?.split(/\r?\n/) ?? [];
66 if (!isOverloadStub(def, lines, overload)) return null;
67 const below = scope.filter((n) => n.startLine > def.startLine).sort((a, b) => a.startLine - b.startLine);
68 return below.find((n) => !isOverloadStub(n, lines, overload))?.id ?? null;
69}
70
71/**
72 * How a file can write typing's `overload` as a decorator: bare names (`overload`,

Callers 1

Calls 6

overloadSpellingsFunction · 0.85
isOverloadStubFunction · 0.85
getNodesInFileNamedMethod · 0.80
getFileLinesMethod · 0.80
getNodesInFileMethod · 0.65
readFileMethod · 0.65

Tested by

no test coverage detected