diff options
| author | Seth Troisi <[email protected]> | 2025-05-01 00:52:01 +0000 |
|---|---|---|
| committer | Seth Troisi <[email protected]> | 2025-05-02 20:58:53 +0000 |
| commit | cc838fad44057a42561215fe3daed2834e6e0442 (patch) | |
| tree | 584251fd75d2d039d3e811fdab3c9d69a2ab0e0f /packages/cli/src/ui/hooks/useCompletion.ts | |
| parent | f237082c37a10db1bf9d7daddf039bf4e002ec61 (diff) | |
Add autocomplete for slash commands
Diffstat (limited to 'packages/cli/src/ui/hooks/useCompletion.ts')
| -rw-r--r-- | packages/cli/src/ui/hooks/useCompletion.ts | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/packages/cli/src/ui/hooks/useCompletion.ts b/packages/cli/src/ui/hooks/useCompletion.ts index 07a71630..31c59bcf 100644 --- a/packages/cli/src/ui/hooks/useCompletion.ts +++ b/packages/cli/src/ui/hooks/useCompletion.ts @@ -12,6 +12,8 @@ import { MAX_SUGGESTIONS_TO_SHOW, Suggestion, } from '../components/SuggestionsDisplay.js'; +import { SlashCommand } from './slashCommandProcessor.js'; + export interface UseCompletionReturn { suggestions: Suggestion[]; activeSuggestionIndex: number; @@ -29,6 +31,7 @@ export function useCompletion( query: string, cwd: string, isActive: boolean, + slashCommands: SlashCommand[], ): UseCompletionReturn { const [suggestions, setSuggestions] = useState<Suggestion[]>([]); const [activeSuggestionIndex, setActiveSuggestionIndex] = @@ -111,6 +114,26 @@ export function useCompletion( return; } + const trimmedQuery = query.trimStart(); // Trim leading whitespace + + // --- Handle Slash Command Completion --- + if (trimmedQuery.startsWith('/')) { + const partialCommand = trimmedQuery.substring(1); + const filteredSuggestions = slashCommands + .map((cmd) => cmd.name) + .filter((name) => name.startsWith(partialCommand)) + .map((name) => ({ label: name, value: name })) + .sort(); + + setSuggestions(filteredSuggestions); + setShowSuggestions(filteredSuggestions.length > 0); + setActiveSuggestionIndex(-1); + setVisibleStartIndex(0); + setIsLoadingSuggestions(false); + return; + } + + // --- Handle At Command Completion --- const atIndex = query.lastIndexOf('@'); if (atIndex === -1) { resetCompletionState(); |
