summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-25 09:09:53 +0300
committerPaul Buetow <paul@buetow.org>2026-05-25 09:09:53 +0300
commit2ebfe46fe6e75aa876cee4fb5b543427ae07a368 (patch)
treec7321f758857de39a086cf4977312aca3b481c16
parent035460d315c71ac78f6741fca6f87ac65c54fb42 (diff)
fix: help <TAB> offers operator topics, not 'help help'
When user types 'help ' (with trailing space), the completer now offers help topic completions (+, dup, swap, etc.). Just 'help' without a space still completes the command normally. Also skip 'help' itself from GetCompletionTopics to avoid suggesting 'help help'.
-rw-r--r--internal/repl/completer.go13
-rw-r--r--internal/repl/help_test.go20
2 files changed, 30 insertions, 3 deletions
diff --git a/internal/repl/completer.go b/internal/repl/completer.go
index ccb4a33..f87209b 100644
--- a/internal/repl/completer.go
+++ b/internal/repl/completer.go
@@ -50,7 +50,7 @@ func NewAutoCompleter() *AutoCompleteAdapter {
// Do implements the readline.AutoCompleter interface.
// It returns matching command completions for the given line.
-// When the first word is "help", it offers help topic completions.
+// When the first word is "help" followed by a space, it offers help topic completions.
func (a *AutoCompleteAdapter) Do(line []rune, pos int) ([][]rune, int) {
text := string(line[:pos])
words := strings.Fields(text)
@@ -58,7 +58,16 @@ func (a *AutoCompleteAdapter) Do(line []rune, pos int) ([][]rune, int) {
return a.completeCommands("")
}
- // If first word is "help", complete help topics
+ // If first word is "help" and user typed a space after it (or more words),
+ // complete help topics. If first word is just "help" with no trailing space,
+ // complete the command "help".
+ if strings.ToLower(words[0]) == "help" && len(words) == 1 {
+ // Check if there's a trailing space — means user wants topics
+ if len(text) > 0 && text[len(text)-1] == ' ' {
+ return a.completeHelpTopics("")
+ }
+ // No trailing space — just completing the command "help"
+ }
if strings.ToLower(words[0]) == "help" && len(words) > 1 {
return a.completeHelpTopics(words[len(words)-1])
}
diff --git a/internal/repl/help_test.go b/internal/repl/help_test.go
index 9813ebb..b537c61 100644
--- a/internal/repl/help_test.go
+++ b/internal/repl/help_test.go
@@ -222,8 +222,26 @@ func TestHelpCompleterIntegration(t *testing.T) {
t.Fatal("NewAutoCompleter returned nil")
}
+ // "help " (with trailing space) should offer help topics, not "help help"
+ matches, _ := adapter.Do([]rune("help "), 5)
+ for _, m := range matches {
+ if string(m) == "help" {
+ t.Error("'help ' should not complete to 'help help'")
+ }
+ }
+ // Should include a known topic
+ foundPlus := false
+ for _, m := range matches {
+ if string(m) == "+" {
+ foundPlus = true
+ }
+ }
+ if !foundPlus {
+ t.Errorf("'help ' should suggest '+', got: %v", matches)
+ }
+
// Test help topic completion
- matches, _ := adapter.Do([]rune("help +"), 6)
+ matches, _ = adapter.Do([]rune("help +"), 6)
if len(matches) != 1 {
t.Errorf("'help +' should match +, got %d matches: %v", len(matches), matches)
}