| 56 | * `null` for the standard library and third-party modules. |
| 57 | */ |
| 58 | export 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) |