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

Function findGoPackageMember

src/resolution/import-resolver.ts:4219–4242  ·  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

4217 * is no project package.
4218 */
4219function findGoPackageMember(
4220 memberName: string,
4221 imp: ImportMapping,
4222 ref: UnresolvedRef,
4223 context: ResolutionContext
4224): ResolvedRef | null {
4225 const pkgDir = context.getGoPackageDir?.(imp.source, ref.filePath);
4226 if (pkgDir == null) return null;
4227 for (const node of context.getNodesByName(memberName)) {
4228 if (node.language !== 'go') continue;
4229 // A method is no member of its package: `pkg.Infof` is the package's
4230 // function, never a method `(*Logger).Infof` declared beside it.
4231 if (!node.isExported || node.kind === 'method') continue;
4232 if (path.posix.dirname(node.filePath.replace(/\\/g, '/')) === pkgDir) {
4233 return {
4234 original: ref,
4235 targetNodeId: node.id,
4236 confidence: 0.9,
4237 resolvedBy: 'import',
4238 };
4239 }
4240 }
4241 return null;
4242}
4243
4244/** Recursive depth cap for re-export chain following. Real codebases
4245 * 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