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

Function implementationOf

src/resolution/python-overloads.ts:58–70  ·  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

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

Callers 1

Calls 6

nodesNamedFunction · 0.90
overloadSpellingsFunction · 0.85
isOverloadStubFunction · 0.85
getNodesInFileNamedMethod · 0.80
getFileLinesMethod · 0.80
readFileMethod · 0.65

Tested by

no test coverage detected