* 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)
| 785 | * is read at most once: every directory the walk passes is memoized. |
| 786 | */ |
| 787 | private nearestGoModule(dir: string): GoModule | null { |
| 788 | const walked: string[] = []; |
| 789 | let found: GoModule | null | undefined; |
| 790 | for (;;) { |
| 791 | found = this.goModuleByDir.get(dir); |
| 792 | if (found !== undefined) break; |
| 793 | walked.push(dir); |
| 794 | found = loadGoModule(path.join(this.projectRoot, dir)); |
| 795 | if (found) this.moduleConfigFiles.add(path.join(this.projectRoot, dir, 'go.mod')); |
| 796 | if (found || dir === '') break; |
| 797 | dir = goDirOf(dir); |
| 798 | } |
| 799 | for (const d of walked) this.goModuleByDir.set(d, found); |
| 800 | return found; |
| 801 | } |
| 802 | |
| 803 | /** |
| 804 | * The project's Go modules: the root `go.mod`'s, and the nearest `go.mod` |