diff --git a/internal/fsext/ls.go b/internal/fsext/ls.go index 2c46416f28a2777ddc9092883686c8a3461a9f7d..333732abbdda8fe1d54892465dc2ab0c244a3889 100644 --- a/internal/fsext/ls.go +++ b/internal/fsext/ls.go @@ -198,6 +198,17 @@ func (dl *directoryLister) getIgnore(path string) ignore.IgnoreParser { }) } +type DirectoryLister func(initialPath string, ignorePatterns []string, limit int) ([]string, bool, error) +type DirectoryListerResolver func() DirectoryLister + +func ResolveDirectoryLister() DirectoryLister { + return listDirectory +} + +func listDirectory(initialPath string, ignorePatterns []string, limit int) ([]string, bool, error) { + return ListDirectory(initialPath, ignorePatterns, limit) +} + // ListDirectory lists files and directories in the specified path, func ListDirectory(initialPath string, ignorePatterns []string, limit int) ([]string, bool, error) { var results []string diff --git a/internal/tui/components/chat/editor/editor.go b/internal/tui/components/chat/editor/editor.go index 8f79fc1c8d72708a489978b93c4447fa63b2cc82..c98b4b81e29c06c133471431867cbb2dce01d14a 100644 --- a/internal/tui/components/chat/editor/editor.go +++ b/internal/tui/components/chat/editor/editor.go @@ -63,6 +63,9 @@ type editorCmp struct { keyMap EditorKeyMap + // injected file dir lister + listDirResolver fsext.DirectoryListerResolver + // File path completions currentQuery string completionsStartIndex int @@ -524,7 +527,7 @@ func (m *editorCmp) SetPosition(x, y int) tea.Cmd { } func (m *editorCmp) startCompletions() tea.Msg { - files, _, _ := fsext.ListDirectory(".", nil, 0) + files, _, _ := m.listDirResolver()(".", nil, 0) slices.Sort(files) completionItems := make([]completions.Completion, 0, len(files)) for _, file := range files { @@ -618,12 +621,13 @@ func newTextArea() *textarea.Model { return ta } -func newEditor(app *app.App) *editorCmp { +func newEditor(app *app.App, resolveDirLister fsext.DirectoryListerResolver) *editorCmp { e := editorCmp{ // TODO: remove the app instance from here app: app, textarea: newTextArea(), keyMap: DefaultEditorKeyMap(), + listDirResolver: resolveDirLister, } e.setEditorPrompt() @@ -634,5 +638,5 @@ func newEditor(app *app.App) *editorCmp { } func New(app *app.App) Editor { - return newEditor(app) + return newEditor(app, fsext.ResolveDirectoryLister) }