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

Function findGoModuleForImport

src/resolution/go-module.ts:58–70  ·  view source on GitHub ↗
(
  importPath: string,
  modules: readonly GoModule[],
  own?: GoModule | null
)

Source from the content-addressed store, hash-verified

56 * `null` for the standard library and third-party modules.
57 */
58export function findGoModuleForImport(
59 importPath: string,
60 modules: readonly GoModule[],
61 own?: GoModule | null
62): GoModule | null {
63 let best: GoModule | null = null;
64 for (const mod of own && !modules.includes(own) ? [...modules, own] : modules) {
65 if (importPath !== mod.modulePath && !importPath.startsWith(`${mod.modulePath}/`)) continue;
66 const length = best ? best.modulePath.length : -1;
67 if (mod.modulePath.length > length || (mod.modulePath.length === length && mod === own)) best = mod;
68 }
69 return best;
70}
71
72/**
73 * The project-relative directory (`/`-separated, `.` for the project root)

Callers 1

createContextMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected