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