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)
| 300 | // It also tries progressively shorter suffixes to handle namespace prefixes |
| 301 | // (e.g. "MyApp/Models" tries "MyApp/Models" first, then "Models"). |
| 302 | func 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 |
| 327 | func detectModule(root string) string { |
no outgoing calls