on main help sign in
fix: improve ignore
84213b1Carlos Alexandro Becker
internal/fsext/ls.go+28−33
@@ -1,8 +1,12 @@
1package fsext
1package fsext
2
2
3import (
3import (
4+ "bytes"
5+ "io"
6+ "log/slog"
4 "os"
7 "os"
5 "path/filepath"
8 "path/filepath"
9+ "strings"
6
10
7 "github.com/charlievieth/fastwalk"
11 "github.com/charlievieth/fastwalk"
8 ignore "github.com/sabhiram/go-gitignore"
12 ignore "github.com/sabhiram/go-gitignore"
@@ -67,10 +71,8 @@ var CommonIgnorePatterns = []string{
67}
71}
68
72
69type DirectoryLister struct {
73type DirectoryLister struct {
70− gitignore *ignore.GitIgnore
71− crushignore *ignore.GitIgnore
72− commonIgnore *ignore.GitIgnore
74+ ignores *ignore.GitIgnore
73− rootPath string
75+ rootPath string
74}
76}
75
77
76func NewDirectoryLister(rootPath string) *DirectoryLister {
78func NewDirectoryLister(rootPath string) *DirectoryLister {
@@ -78,26 +80,29 @@ func NewDirectoryLister(rootPath string) *DirectoryLister {
78 rootPath: rootPath,
80 rootPath: rootPath,
79 }
81 }
80
82
81− // Load gitignore if it exists
83+ dl.ignores = ignore.CompileIgnoreLines(append(CommonIgnorePatterns, strings.Split(parseIgnores(rootPath), "\n")...)...)
82− gitignorePath := filepath.Join(rootPath, ".gitignore")
84+
83− if _, err := os.Stat(gitignorePath); err == nil {
85+ return dl
84− if gi, err := ignore.CompileIgnoreFile(gitignorePath); err == nil {
85− dl.gitignore = gi
86− }
87− }
86+}
88
87
89− // Load crushignore if it exists
88+func parseIgnores(path string) string {
90− crushignorePath := filepath.Join(rootPath, ".crushignore")
89+ var b bytes.Buffer
90+ for _, ign := range []string{".crushignore", ".gitignore"} {
91+ p := filepath.Join(path, ign)
91− if _, err := os.Stat(crushignorePath); err == nil {
92+ if _, err := os.Stat(p); err == nil {
92− if ci, err := ignore.CompileIgnoreFile(crushignorePath); err == nil {
93+ f, err := os.Open(p)
93− dl.crushignore = ci
94+ if err != nil {
95+ _ = f.Close()
96+ slog.Error("Failed to open ignore file", "path", p, "error", err)
97+ continue
98+ }
99+ if _, err := io.Copy(&b, f); err != nil {
100+ slog.Error("Failed to read ignore file", "path", p, "error", err)
101+ }
102+ _ = f.Close()
94 }
103 }
95 }
104 }
96−
105+ return b.String()
97− // Create common ignore patterns
98− dl.commonIgnore = ignore.CompileIgnoreLines(CommonIgnorePatterns...)
99−
100− return dl
101}
106}
102
107
103func (dl *DirectoryLister) shouldIgnore(path string, ignorePatterns []string) bool {
108func (dl *DirectoryLister) shouldIgnore(path string, ignorePatterns []string) bool {
@@ -106,18 +111,7 @@ func (dl *DirectoryLister) shouldIgnore(path string, ignorePatterns []string) bo
106 relPath = path
111 relPath = path
107 }
112 }
108
113
109− // Check common ignore patterns
110− if dl.commonIgnore.MatchesPath(relPath) {
111− return true
112− }
113−
114− // Check gitignore patterns if available
115− if dl.gitignore != nil && dl.gitignore.MatchesPath(relPath) {
116− return true
117− }
118−
119− // Check crushignore patterns if available
120− if dl.crushignore != nil && dl.crushignore.MatchesPath(relPath) {
114+ if dl.ignores.MatchesPath(relPath) {
121 return true
115 return true
122 }
116 }
123
117
@@ -144,6 +138,7 @@ func ListDirectory(initialPath string, ignorePatterns []string, limit int) ([]st
144 ToSlash: fastwalk.DefaultToSlash(),
138 ToSlash: fastwalk.DefaultToSlash(),
145 Sort: fastwalk.SortDirsFirst,
139 Sort: fastwalk.SortDirsFirst,
146 }
140 }
141+
147 err := fastwalk.Walk(&conf, initialPath, func(path string, d os.DirEntry, err error) error {
142 err := fastwalk.Walk(&conf, initialPath, func(path string, d os.DirEntry, err error) error {
148 if err != nil {
143 if err != nil {
149 return nil // Skip files we don't have permission to access
144 return nil // Skip files we don't have permission to access
internal/tui/components/chat/editor/editor.go+1−1
@@ -473,7 +473,7 @@ func (m *editorCmp) SetPosition(x, y int) tea.Cmd {
473}
473}
474
474
475func (m *editorCmp) startCompletions() tea.Msg {
475func (m *editorCmp) startCompletions() tea.Msg {
476− files, _, _ := fsext.ListDirectory(".", []string{}, 0)
476+ files, _, _ := fsext.ListDirectory(".", nil, 0)
477 completionItems := make([]completions.Completion, 0, len(files))
477 completionItems := make([]completions.Completion, 0, len(files))
478 for _, file := range files {
478 for _, file := range files {
479 file = strings.TrimPrefix(file, "./")
479 file = strings.TrimPrefix(file, "./")