diff options
Diffstat (limited to 'internal/repl')
| -rw-r--r-- | internal/repl/completer.go | 13 | ||||
| -rw-r--r-- | internal/repl/help_test.go | 20 |
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) } |
