* Get completions for the given shell type
( shellType: 'bash' | 'zsh', prefix: string, completionType: ShellCompletionType, abortSignal: AbortSignal, )
| 182 | * Get completions for the given shell type |
| 183 | */ |
| 184 | async function getCompletionsForShell( |
| 185 | shellType: 'bash' | 'zsh', |
| 186 | prefix: string, |
| 187 | completionType: ShellCompletionType, |
| 188 | abortSignal: AbortSignal, |
| 189 | ): Promise<SuggestionItem[]> { |
| 190 | let command: string |
| 191 | |
| 192 | if (shellType === 'bash') { |
| 193 | command = getBashCompletionCommand(prefix, completionType) |
| 194 | } else if (shellType === 'zsh') { |
| 195 | command = getZshCompletionCommand(prefix, completionType) |
| 196 | } else { |
| 197 | // Unsupported shell type |
| 198 | return [] |
| 199 | } |
| 200 | |
| 201 | const shellCommand = await Shell.exec(command, abortSignal, 'bash', { |
| 202 | timeout: SHELL_COMPLETION_TIMEOUT_MS, |
| 203 | }) |
| 204 | const result = await shellCommand.result |
| 205 | return result.stdout |
| 206 | .split('\n') |
| 207 | .filter((line: string) => line.trim()) |
| 208 | .slice(0, MAX_SHELL_COMPLETIONS) |
| 209 | .map((text: string) => ({ |
| 210 | id: text, |
| 211 | displayText: text, |
| 212 | description: undefined, |
| 213 | metadata: { completionType }, |
| 214 | })) |
| 215 | } |
| 216 | |
| 217 | /** |
| 218 | * Get shell completions for the given input |
no test coverage detected