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

Function tryDirMatch

scanner/filegraph.go:302–324  ·  view source on GitHub ↗

tryDirMatch returns all files whose parent directory matches the given path. This resolves namespace-level imports (e.g. C# "using Foo.Bar;" -> "Foo/Bar/") where an import refers to a whole directory rather than a single file. It also tries progressively shorter suffixes to handle namespace prefixes

(path string, idx *fileIndex)

Source from the content-addressed store, hash-verified

300// It also tries progressively shorter suffixes to handle namespace prefixes
301// (e.g. "MyApp/Models" tries "MyApp/Models" first, then "Models").
302func tryDirMatch(path string, idx *fileIndex) []string {
303 // Try exact match first
304 if files, ok := idx.byDir[path]; ok {
305 return files
306 }
307 // Normalize path separators for cross-platform compatibility
308 nativePath := filepath.FromSlash(path)
309 if nativePath != path {
310 if files, ok := idx.byDir[nativePath]; ok {
311 return files
312 }
313 }
314 // Try suffix match: strip leading segments progressively
315 // This handles namespace prefixes like MyApp.Models -> Models
316 parts := strings.Split(filepath.ToSlash(path), "/")
317 for i := 1; i < len(parts); i++ {
318 suffix := filepath.Join(parts[i:]...)
319 if files, ok := idx.byDir[suffix]; ok {
320 return files
321 }
322 }
323 return nil
324}
325
326// detectModule reads go.mod to find the module name
327func detectModule(root string) string {

Callers 2

fuzzyResolveFunction · 0.85
TestTryDirMatchFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestTryDirMatchFunction · 0.68