From 6ddd5abd7bbce0d3fc9acbd6daa1083ec81c26f3 Mon Sep 17 00:00:00 2001 From: Sandy Tao Date: Wed, 17 Dec 2025 12:30:35 -1000 Subject: [PATCH] fix(ui): Prevent eager slash command completion hiding sibling commands (#15224) --- .../src/ui/hooks/useSlashCompletion.test.ts | 48 ++++++++++++++++++- .../cli/src/ui/hooks/useSlashCompletion.ts | 6 --- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/packages/cli/src/ui/hooks/useSlashCompletion.test.ts b/packages/cli/src/ui/hooks/useSlashCompletion.test.ts index 68548a0758..41af410f35 100644 --- a/packages/cli/src/ui/hooks/useSlashCompletion.test.ts +++ b/packages/cli/src/ui/hooks/useSlashCompletion.test.ts @@ -530,6 +530,52 @@ describe('useSlashCompletion', () => { unmount(); }); + it('should suggest parent command (and siblings) instead of sub-commands when no trailing space', async () => { + const slashCommands = [ + createTestCommand({ + name: 'memory', + description: 'Manage memory', + subCommands: [ + createTestCommand({ name: 'show', description: 'Show memory' }), + ], + }), + createTestCommand({ + name: 'memory-leak', + description: 'Debug memory leaks', + }), + ]; + + const { result } = renderHook(() => + useTestHarnessForSlashCompletion( + true, + '/memory', + slashCommands, + mockCommandContext, + ), + ); + + // Should verify that we see BOTH 'memory' and 'memory-leak' + await waitFor(() => { + expect(result.current.suggestions).toHaveLength(2); + expect(result.current.suggestions).toEqual( + expect.arrayContaining([ + { + label: 'memory', + value: 'memory', + description: 'Manage memory', + commandKind: CommandKind.BUILT_IN, + }, + { + label: 'memory-leak', + value: 'memory-leak', + description: 'Debug memory leaks', + commandKind: CommandKind.BUILT_IN, + }, + ]), + ); + }); + }); + it('should suggest all sub-commands when the query ends with the parent command and a space', async () => { const slashCommands = [ createTestCommand({ @@ -892,7 +938,7 @@ describe('useSlashCompletion', () => { const { result, unmount } = renderHook(() => useTestHarnessForSlashCompletion( true, - '/memory', + '/memory ', slashCommands, mockCommandContext, ), diff --git a/packages/cli/src/ui/hooks/useSlashCompletion.ts b/packages/cli/src/ui/hooks/useSlashCompletion.ts index 50ac9611bb..0a6f49e597 100644 --- a/packages/cli/src/ui/hooks/useSlashCompletion.ts +++ b/packages/cli/src/ui/hooks/useSlashCompletion.ts @@ -117,12 +117,6 @@ function useCommandParser( exactMatchAsParent = currentLevel.find( (cmd) => matchesCommand(cmd, partial) && cmd.subCommands, ); - - if (exactMatchAsParent) { - leafCommand = exactMatchAsParent; - currentLevel = exactMatchAsParent.subCommands; - partial = ''; - } } const depth = commandPathParts.length;