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

Method nearestGoModule

src/resolution/index.ts:899–913  ·  view source on GitHub ↗

* The module of the nearest `go.mod` at or above project-relative `dir` * ('' = the root), never above the project root (#2322). Each directory * is read at most once: every directory the walk passes is memoized.

(dir: string)

Source from the content-addressed store, hash-verified

897 * is read at most once: every directory the walk passes is memoized.
898 */
899 private nearestGoModule(dir: string): GoModule | null {
900 const walked: string[] = [];
901 let found: GoModule | null | undefined;
902 for (;;) {
903 found = this.goModuleByDir.get(dir);
904 if (found !== undefined) break;
905 walked.push(dir);
906 found = loadGoModule(path.join(this.projectRoot, dir));
907 if (found) this.moduleConfigFiles.add(path.join(this.projectRoot, dir, 'go.mod'));
908 if (found || dir === '') break;
909 dir = goDirOf(dir);
910 }
911 for (const d of walked) this.goModuleByDir.set(d, found);
912 return found;
913 }
914
915 /**
916 * The project's Go modules: the root `go.mod`'s, and the nearest `go.mod`

Callers 2

getGoModulesMethod · 0.95
createContextMethod · 0.95

Calls 7

loadGoModuleFunction · 0.90
goDirOfFunction · 0.85
pushMethod · 0.80
getMethod · 0.65
joinMethod · 0.45
addMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected