fuzzyResolve converts an import path to actual file paths using universal matching No language-specific switch - relies on pattern matching against file index
(imp, fromFile string, idx *fileIndex, goModule string, pathAliases map[string][]string, baseURL string)
| 156 | // fuzzyResolve converts an import path to actual file paths using universal matching |
| 157 | // No language-specific switch - relies on pattern matching against file index |
| 158 | func fuzzyResolve(imp, fromFile string, idx *fileIndex, goModule string, pathAliases map[string][]string, baseURL string) []string { |
| 159 | fromDir := filepath.Dir(fromFile) |
| 160 | if fromDir == "." { |
| 161 | fromDir = "" |
| 162 | } |
| 163 | |
| 164 | // Normalize the import path |
| 165 | normalized := normalizeImport(imp) |
| 166 | |
| 167 | // Strategy 1: Go package lookup (if it looks like a Go module import) |
| 168 | if goModule != "" && strings.HasPrefix(imp, goModule) { |
| 169 | if files, ok := idx.goPkgs[imp]; ok { |
| 170 | return files |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | // Strategy 2: Relative path resolution (./foo, ../bar) |
| 175 | if strings.HasPrefix(imp, ".") { |
| 176 | return resolveRelative(imp, fromDir, idx) |
| 177 | } |
| 178 | |
| 179 | // Strategy 3: TypeScript/JavaScript path alias resolution (@modules/auth, @shared/utils) |
| 180 | if len(pathAliases) > 0 { |
| 181 | if files := resolvePathAlias(imp, pathAliases, baseURL, idx); len(files) > 0 { |
| 182 | return files |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | // Strategy 4: Exact match (with common extensions) |
| 187 | if files := tryExactMatch(normalized, idx); len(files) > 0 { |
| 188 | return files |
| 189 | } |
| 190 | |
| 191 | // Strategy 5: Suffix match (for nested packages like app.core.config -> */app/core/config.py) |
| 192 | if files := trySuffixMatch(normalized, idx); len(files) > 0 { |
| 193 | return files |
| 194 | } |
| 195 | |
| 196 | // Strategy 6: Directory match (for namespace-level imports like C# "using Foo.Bar;" |
| 197 | // where Foo.Bar normalizes to Foo/Bar and maps to the Foo/Bar/ directory). |
| 198 | if files := tryDirMatch(normalized, idx); len(files) > 0 { |
| 199 | return files |
| 200 | } |
| 201 | |
| 202 | return nil |
| 203 | } |
| 204 | |
| 205 | // normalizeImport converts various import syntaxes to a path-like format |
| 206 | func normalizeImport(imp string) string { |