initial commit
This commit is contained in:
38
indexer/walker.go
Normal file
38
indexer/walker.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user