* 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)
| 883 | * is read at most once: every directory the walk passes is memoized. |
| 884 | */ |
| 885 | private nearestGoModule(dir: string): GoModule | null { |
| 886 | const walked: string[] = []; |
| 887 | let found: GoModule | null | undefined; |
| 888 | for (;;) { |
| 889 | found = this.goModuleByDir.get(dir); |
| 890 | if (found !== undefined) break; |
| 891 | walked.push(dir); |
| 892 | found = loadGoModule(path.join(this.projectRoot, dir)); |
| 893 | if (found) this.moduleConfigFiles.add(path.join(this.projectRoot, dir, 'go.mod')); |
| 894 | if (found || dir === '') break; |
| 895 | dir = goDirOf(dir); |
| 896 | } |
| 897 | for (const d of walked) this.goModuleByDir.set(d, found); |
| 898 | return found; |
| 899 | } |
| 900 | |
| 901 | /** |
| 902 | * The project's Go modules: the root `go.mod`'s, and the nearest `go.mod` |