MCPcopy Create free account
hub / github.com/codehamr/codehamr / refreshSuggest

Method refreshSuggest

internal/tui/popover.go:34–75  ·  view source on GitHub ↗

refreshSuggest recomputes the popover from the textarea: command level before the first space, argument level after it.

()

Source from the content-addressed store, hash-verified

32// refreshSuggest recomputes the popover from the textarea: command level before
33// the first space, argument level after it.
34func (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.

Callers 2

forwardToTextareaMethod · 0.95
setPromptTextMethod · 0.95

Calls 6

closePopoverMethod · 0.95
setPopoverMethod · 0.95
reloadConfigFromDiskMethod · 0.95
commandByNameFunction · 0.85
ValueMethod · 0.80
activeMethod · 0.80

Tested by

no test coverage detected