initial commit

This commit is contained in:
2026-04-10 15:31:52 -04:00
commit 39fcfc2968
18 changed files with 1066 additions and 0 deletions

38
indexer/walker.go Normal file
View File

@@ -0,0 +1,38 @@
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
}