package indexer import ( "bytes" "os/exec" "strings" "github.com/odvcencio/gotreesitter/grammars" ) // WalkFiles returns all git-tracked files that tree-sitter can parse. // It uses `git ls-files` to respect .gitignore rules correctly. func WalkFiles(root string) ([]string, error) { cmd := exec.Command("git", "ls-files", "--cached", "--others", "--exclude-standard") cmd.Dir = root out, err := cmd.Output() if err != nil { return nil, err } var files []string for _, line := range bytes.Split(out, []byte("\n")) { relPath := strings.TrimSpace(string(line)) if relPath == "" { continue } // Check if tree-sitter can handle this file // DetectLanguage works on filename, not full path parts := strings.Split(relPath, "/") filename := parts[len(parts)-1] if entry := grammars.DetectLanguage(filename); entry != nil { files = append(files, relPath) } } return files, nil }