on main help sign in
chore: add completions help and small improvements
5bf5eacKujtim Hoxha
internal/tui/components/chat/editor/editor.go+5
@@ -35,6 +35,7 @@ type Editor interface {
35 layout.Positional
35 layout.Positional
36
36
37 SetSession(session session.Session) tea.Cmd
37 SetSession(session session.Session) tea.Cmd
38+ IsCompletionsOpen() bool
38 Cursor() *tea.Cursor
39 Cursor() *tea.Cursor
39}
40}
40
41
@@ -391,6 +392,10 @@ func (c *editorCmp) SetSession(session session.Session) tea.Cmd {
391 return nil
392 return nil
392}
393}
393
394
395+func (c *editorCmp) IsCompletionsOpen() bool {
396+ return c.isCompletionsOpen
397+}
398+
394func New(app *app.App) Editor {
399func New(app *app.App) Editor {
395 t := styles.CurrentTheme()
400 t := styles.CurrentTheme()
396 ta := textarea.New()
401 ta := textarea.New()
internal/tui/components/completions/completions.go+7−3
@@ -70,8 +70,8 @@ func New() Completions {
70 list.WithHideFilterInput(true),
70 list.WithHideFilterInput(true),
71 )
71 )
72 return &completionsCmp{
72 return &completionsCmp{
73− width: 30,
73+ width: 0,
74− height: 10,
74+ height: 0,
75 list: l,
75 list: l,
76 query: "",
76 query: "",
77 keyMap: completionsKeyMap,
77 keyMap: completionsKeyMap,
@@ -89,6 +89,10 @@ func (c *completionsCmp) Init() tea.Cmd {
89// Update implements Completions.
89// Update implements Completions.
90func (c *completionsCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
90func (c *completionsCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
91 switch msg := msg.(type) {
91 switch msg := msg.(type) {
92+ case tea.WindowSizeMsg:
93+ c.width = min(msg.Width-c.x, 80)
94+ c.height = min(msg.Height-c.y, 15)
95+ return c, nil
92 case tea.KeyPressMsg:
96 case tea.KeyPressMsg:
93 switch {
97 switch {
94 case key.Matches(msg, c.keyMap.Up):
98 case key.Matches(msg, c.keyMap.Up):
@@ -135,7 +139,7 @@ func (c *completionsCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
135 item := NewCompletionItem(completion.Title, completion.Value, WithBackgroundColor(t.BgSubtle))
139 item := NewCompletionItem(completion.Title, completion.Value, WithBackgroundColor(t.BgSubtle))
136 items = append(items, item)
140 items = append(items, item)
137 }
141 }
138− c.height = max(min(10, len(items)), 1) // Ensure at least 1 item height
142+ c.height = max(min(c.height, len(items)), 1) // Ensure at least 1 item height
139 cmds := []tea.Cmd{
143 cmds := []tea.Cmd{
140 c.list.SetSize(c.width, c.height),
144 c.list.SetSize(c.width, c.height),
141 c.list.SetItems(items),
145 c.list.SetItems(items),
internal/tui/components/completions/item.go+1
@@ -90,6 +90,7 @@ func (c *completionItemCmp) View() string {
90 if c.bgColor != nil {
90 if c.bgColor != nil {
91 titleStyle = titleStyle.Background(c.bgColor)
91 titleStyle = titleStyle.Background(c.bgColor)
92 titleMatchStyle = titleMatchStyle.Background(c.bgColor)
92 titleMatchStyle = titleMatchStyle.Background(c.bgColor)
93+ itemStyle = itemStyle.Background(c.bgColor)
93 }
94 }
94
95
95 if c.focus {
96 if c.focus {
internal/tui/components/completions/keys.go+1−1
@@ -22,7 +22,7 @@ func DefaultKeyMap() KeyMap {
22 key.WithHelp("up", "move up"),
22 key.WithHelp("up", "move up"),
23 ),
23 ),
24 Select: key.NewBinding(
24 Select: key.NewBinding(
25− key.WithKeys("enter"),
25+ key.WithKeys("enter", "tab", "ctrl+y"),
26 key.WithHelp("enter", "select"),
26 key.WithHelp("enter", "select"),
27 ),
27 ),
28 Cancel: key.NewBinding(
28 Cancel: key.NewBinding(
internal/tui/page/chat/chat.go+20
@@ -657,6 +657,26 @@ func (a *chatPage) Help() help.KeyMap {
657 fullList = append(fullList, []key.Binding{v})
657 fullList = append(fullList, []key.Binding{v})
658 }
658 }
659 default:
659 default:
660+ if a.editor.IsCompletionsOpen() {
661+ shortList = append(shortList,
662+ key.NewBinding(
663+ key.WithKeys("tab", "enter"),
664+ key.WithHelp("tab/enter", "complete"),
665+ ),
666+ key.NewBinding(
667+ key.WithKeys("esc"),
668+ key.WithHelp("esc", "cancel"),
669+ ),
670+ key.NewBinding(
671+ key.WithKeys("up", "down"),
672+ key.WithHelp("↑/↓", "choose"),
673+ ),
674+ )
675+ for _, v := range shortList {
676+ fullList = append(fullList, []key.Binding{v})
677+ }
678+ return core.NewSimpleHelp(shortList, fullList)
679+ }
660 if a.app.CoderAgent != nil && a.app.CoderAgent.IsBusy() {
680 if a.app.CoderAgent != nil && a.app.CoderAgent.IsBusy() {
661 cancelBinding := key.NewBinding(
681 cancelBinding := key.NewBinding(
662 key.WithKeys("esc"),
682 key.WithKeys("esc"),
internal/tui/tui.go+4−1
@@ -109,6 +109,7 @@ func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
109 }
109 }
110 return a, tea.Batch(cmds...)
110 return a, tea.Batch(cmds...)
111 case tea.WindowSizeMsg:
111 case tea.WindowSizeMsg:
112+ a.completions.Update(msg)
112 return a, a.handleWindowResize(msg.Width, msg.Height)
113 return a, a.handleWindowResize(msg.Width, msg.Height)
113
114
114 // Completions messages
115 // Completions messages
@@ -119,9 +120,11 @@ func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
119
120
120 // Dialog messages
121 // Dialog messages
121 case dialogs.OpenDialogMsg, dialogs.CloseDialogMsg:
122 case dialogs.OpenDialogMsg, dialogs.CloseDialogMsg:
123+ u, completionCmd := a.completions.Update(completions.CloseCompletionsMsg{})
124+ a.completions = u.(completions.Completions)
122 u, dialogCmd := a.dialog.Update(msg)
125 u, dialogCmd := a.dialog.Update(msg)
123 a.dialog = u.(dialogs.DialogCmp)
126 a.dialog = u.(dialogs.DialogCmp)
124− return a, dialogCmd
127+ return a, tea.Batch(completionCmd, dialogCmd)
125 case commands.ShowArgumentsDialogMsg:
128 case commands.ShowArgumentsDialogMsg:
126 return a, util.CmdHandler(
129 return a, util.CmdHandler(
127 dialogs.OpenDialogMsg{
130 dialogs.OpenDialogMsg{