on main help sign in
fix(ui): completions: load files asynchronously
commit6a5746354cd9998fabadf57dc9c9ce0a91023e4c authorAyman Bagabas <ayman.bagabas@gmail.com> dateThu 8 Jan 2026, 11:25 (9 months ago) parentc4cdc5d
2 files changed+17−5
internal/ui/completions/completions.go+11−4 internal/ui/model/ui.go+6−1
internal/ui/completions/completions.go+11−4
@@ -29,6 +29,11 @@ type SelectionMsg struct {
2929// ClosedMsg is sent when the completions are closed.
3030type ClosedMsg struct{}
3131
32+// FilesLoadedMsg is sent when files have been loaded for completions.
33+type FilesLoadedMsg struct {
34+ Files []string
35+}
36+
3237// Completions represents the completions popup component.
3338type Completions struct {
3439 // Popup dimensions
@@ -88,10 +93,12 @@ func (c *Completions) KeyMap() KeyMap {
8893}
8994
9095// OpenWithFiles opens the completions with file items from the filesystem.
91−func (c *Completions) OpenWithFiles(depth, limit int) {
92− files, _, _ := fsext.ListDirectory(".", nil, depth, limit)
93− slices.Sort(files)
94− c.SetFiles(files)
96+func (c *Completions) OpenWithFiles(depth, limit int) tea.Cmd {
97+ return func() tea.Msg {
98+ files, _, _ := fsext.ListDirectory(".", nil, depth, limit)
99+ slices.Sort(files)
100+ return FilesLoadedMsg{Files: files}
101+ }
95102}
96103
97104// SetFiles sets the file items on the completions popup.
internal/ui/model/ui.go+6−1
@@ -371,6 +371,11 @@ func (m *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
371371 cmds = append(cmds, clearInfoMsgCmd(ttl))
372372 case uiutil.ClearStatusMsg:
373373 m.status.ClearInfoMsg()
374+ case completions.FilesLoadedMsg:
375+ // Handle async file loading for completions.
376+ if m.completionsOpen {
377+ m.completions.SetFiles(msg.Files)
378+ }
374379 }
375380
376381 // This logic gets triggered on any message type, but should it?
@@ -878,7 +883,7 @@ func (m *UI) handleKeyPressMsg(msg tea.KeyPressMsg) tea.Cmd {
878883 m.completionsStartIndex = curIdx
879884 m.completionsPositionStart = m.completionsPosition()
880885 depth, limit := m.com.Config().Options.TUI.Completions.Limits()
881− m.completions.OpenWithFiles(depth, limit)
886+ cmds = append(cmds, m.completions.OpenWithFiles(depth, limit))
882887 }
883888 }
884889