refreshSuggest recomputes the popover from the textarea: command level before the first space, argument level after it.
()
| 32 | // refreshSuggest recomputes the popover from the textarea: command level before |
| 33 | // the first space, argument level after it. |
| 34 | func (m *Model) refreshSuggest() { |
| 35 | text := m.ta.Value() |
| 36 | if strings.Contains(text, "\n") || !strings.HasPrefix(text, "/") { |
| 37 | m.closePopover() |
| 38 | return |
| 39 | } |
| 40 | |
| 41 | cmdName, rest, hasSpace := strings.Cut(text, " ") |
| 42 | if !hasSpace { |
| 43 | var ms []argOption |
| 44 | for _, c := range commands { |
| 45 | if strings.HasPrefix(c.name, text) { |
| 46 | ms = append(ms, argOption{value: c.name, description: c.description}) |
| 47 | } |
| 48 | } |
| 49 | m.setPopover(ms, false, "") |
| 50 | return |
| 51 | } |
| 52 | |
| 53 | c := commandByName(cmdName) |
| 54 | if c == nil || c.args == nil { |
| 55 | m.closePopover() |
| 56 | return |
| 57 | } |
| 58 | // Reload cfg on the cmd→arg transition (or a different arg level command) so |
| 59 | // lists like /models <name> reflect external edits before submit. Errors are |
| 60 | // silent: runSlash surfaces them on submit, not on every keystroke. Never |
| 61 | // mid turn: a reload can rebuildClient and swap the live client |
| 62 | // under the in flight turn; submit is phase gated anyway, so |
| 63 | // runSlash's own reload covers correctness once the turn is over. |
| 64 | if !m.phase.active() && (!m.suggestArgLevel || m.activeCmd != cmdName) { |
| 65 | _ = m.reloadConfigFromDisk() |
| 66 | } |
| 67 | argPrefix := strings.TrimLeft(rest, " ") |
| 68 | var ms []argOption |
| 69 | for _, o := range c.args(*m) { |
| 70 | if strings.HasPrefix(o.value, argPrefix) { |
| 71 | ms = append(ms, o) |
| 72 | } |
| 73 | } |
| 74 | m.setPopover(ms, true, cmdName) |
| 75 | } |
| 76 | |
| 77 | // setPopover swaps in a new suggestion set. Selection priority: the current row |
| 78 | // (e.g. active profile), else the first. |
no test coverage detected