MCPcopy Create free account
hub / github.com/JordanCoin/codemap / fuzzyResolve

Function fuzzyResolve

scanner/filegraph.go:158–203  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
158func 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
206func normalizeImport(imp string) string {

Callers 4

TestDepsFuzzyResolveFunction · 0.85
TestFuzzyResolveFunction · 0.85

Calls 6

normalizeImportFunction · 0.85
resolveRelativeFunction · 0.85
resolvePathAliasFunction · 0.85
tryExactMatchFunction · 0.85
trySuffixMatchFunction · 0.85
tryDirMatchFunction · 0.85

Tested by 3

TestDepsFuzzyResolveFunction · 0.68
TestFuzzyResolveFunction · 0.68