MCPcopy
hub / github.com/codeaashu/claude-code / getBestCommandMatch

Function getBestCommandMatch

src/utils/suggestions/commandSuggestions.ts:164–195  ·  view source on GitHub ↗
(
  partialCommand: string,
  commands: Command[],
)

Source from the content-addressed store, hash-verified

162 * @returns The completion suffix (e.g., "mit" for partial "com" matching "commit"), or null
163 */
164export 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)

Callers 1

useTypeaheadFunction · 0.85

Calls 3

isCommandMetadataFunction · 0.85
getCommandNameFunction · 0.50

Tested by

no test coverage detected