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

Function findGoPackageMember

src/resolution/import-resolver.ts:4420–4443  ·  view source on GitHub ↗

* The exported `memberName` of the project package `imp` names, looked up in * the package's directory: its module's directory followed by the rest of * the import path (#2322). Matched on the immediate directory so `pkga.FuncX` * never lands on a `FuncX` declared in `pkga/subpkg/`. Null when the

(
  memberName: string,
  imp: ImportMapping,
  ref: UnresolvedRef,
  context: ResolutionContext
)

Source from the content-addressed store, hash-verified

4418 * is no project package.
4419 */
4420function findGoPackageMember(
4421 memberName: string,
4422 imp: ImportMapping,
4423 ref: UnresolvedRef,
4424 context: ResolutionContext
4425): ResolvedRef | null {
4426 const pkgDir = context.getGoPackageDir?.(imp.source, ref.filePath);
4427 if (pkgDir == null) return null;
4428 for (const node of context.getNodesByName(memberName)) {
4429 if (node.language !== 'go') continue;
4430 // A method is no member of its package: `pkg.Infof` is the package's
4431 // function, never a method `(*Logger).Infof` declared beside it.
4432 if (!node.isExported || node.kind === 'method') continue;
4433 if (path.posix.dirname(node.filePath.replace(/\\/g, '/')) === pkgDir) {
4434 return {
4435 original: ref,
4436 targetNodeId: node.id,
4437 confidence: 0.9,
4438 resolvedBy: 'import',
4439 };
4440 }
4441 }
4442 return null;
4443}
4444
4445/** Recursive depth cap for re-export chain following. Real codebases
4446 * rarely chain barrels more than 2–3 deep; 8 is a generous safety

Callers 1

Calls 2

getGoPackageDirMethod · 0.80
getNodesByNameMethod · 0.65

Tested by

no test coverage detected