( partialCommand: string, commands: Command[], )
| 162 | * @returns The completion suffix (e.g., "mit" for partial "com" matching "commit"), or null |
| 163 | */ |
| 164 | export function getBestCommandMatch( |
| 165 | partialCommand: string, |
| 166 | commands: Command[], |
| 167 | ): { suffix: string; fullCommand: string } | null { |
| 168 | if (!partialCommand) { |
| 169 | return null |
| 170 | } |
| 171 | |
| 172 | // Use existing suggestion logic |
| 173 | const suggestions = generateCommandSuggestions('/' + partialCommand, commands) |
| 174 | if (suggestions.length === 0) { |
| 175 | return null |
| 176 | } |
| 177 | |
| 178 | // Find first suggestion that is a prefix match (for inline completion) |
| 179 | const query = partialCommand.toLowerCase() |
| 180 | for (const suggestion of suggestions) { |
| 181 | if (!isCommandMetadata(suggestion.metadata)) { |
| 182 | continue |
| 183 | } |
| 184 | const name = getCommandName(suggestion.metadata) |
| 185 | if (name.toLowerCase().startsWith(query)) { |
| 186 | const suffix = name.slice(partialCommand.length) |
| 187 | // Only return if there's something to complete |
| 188 | if (suffix) { |
| 189 | return { suffix, fullCommand: name } |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | return null |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * Checks if input is a command (starts with slash) |
no test coverage detected