diff options
Diffstat (limited to 'packages/cli/src/ui/hooks/useCompletion.ts')
| -rw-r--r-- | packages/cli/src/ui/hooks/useCompletion.ts | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/packages/cli/src/ui/hooks/useCompletion.ts b/packages/cli/src/ui/hooks/useCompletion.ts index 69d8bfb9..aacc111d 100644 --- a/packages/cli/src/ui/hooks/useCompletion.ts +++ b/packages/cli/src/ui/hooks/useCompletion.ts @@ -41,7 +41,7 @@ export function useCompletion( query: string, cwd: string, isActive: boolean, - slashCommands: SlashCommand[], + slashCommands: readonly SlashCommand[], commandContext: CommandContext, config?: Config, ): UseCompletionReturn { @@ -151,7 +151,7 @@ export function useCompletion( } // Traverse the Command Tree using the tentative completed path - let currentLevel: SlashCommand[] | undefined = slashCommands; + let currentLevel: readonly SlashCommand[] | undefined = slashCommands; let leafCommand: SlashCommand | null = null; for (const part of commandPathParts) { @@ -161,11 +161,13 @@ export function useCompletion( break; } const found: SlashCommand | undefined = currentLevel.find( - (cmd) => cmd.name === part || cmd.altName === part, + (cmd) => cmd.name === part || cmd.altNames?.includes(part), ); if (found) { leafCommand = found; - currentLevel = found.subCommands; + currentLevel = found.subCommands as + | readonly SlashCommand[] + | undefined; } else { leafCommand = null; currentLevel = []; @@ -177,7 +179,7 @@ export function useCompletion( if (!hasTrailingSpace && currentLevel) { const exactMatchAsParent = currentLevel.find( (cmd) => - (cmd.name === partial || cmd.altName === partial) && + (cmd.name === partial || cmd.altNames?.includes(partial)) && cmd.subCommands, ); @@ -199,7 +201,8 @@ export function useCompletion( // Case: /command subcommand<enter> const perfectMatch = currentLevel.find( (cmd) => - (cmd.name === partial || cmd.altName === partial) && cmd.action, + (cmd.name === partial || cmd.altNames?.includes(partial)) && + cmd.action, ); if (perfectMatch) { setIsPerfectMatch(true); @@ -238,14 +241,15 @@ export function useCompletion( let potentialSuggestions = commandsToSearch.filter( (cmd) => cmd.description && - (cmd.name.startsWith(partial) || cmd.altName?.startsWith(partial)), + (cmd.name.startsWith(partial) || + cmd.altNames?.some((alt) => alt.startsWith(partial))), ); // If a user's input is an exact match and it is a leaf command, // enter should submit immediately. if (potentialSuggestions.length > 0 && !hasTrailingSpace) { const perfectMatch = potentialSuggestions.find( - (s) => s.name === partial || s.altName === partial, + (s) => s.name === partial || s.altNames?.includes(partial), ); if (perfectMatch && perfectMatch.action) { potentialSuggestions = []; |
