( query: string, selectedType: ContextMenuOptionType | null = null, queryItems: ContextMenuQueryItem[], dynamicSearchResults: SearchResult[] = [], modes?: ModeConfig[], commands?: Command[], )
| 122 | } |
| 123 | |
| 124 | export function getContextMenuOptions( |
| 125 | query: string, |
| 126 | selectedType: ContextMenuOptionType | null = null, |
| 127 | queryItems: ContextMenuQueryItem[], |
| 128 | dynamicSearchResults: SearchResult[] = [], |
| 129 | modes?: ModeConfig[], |
| 130 | commands?: Command[], |
| 131 | ): ContextMenuQueryItem[] { |
| 132 | // Handle slash commands for modes and commands |
| 133 | // Only process as slash command if the query itself starts with "/" (meaning we're typing a slash command) |
| 134 | if (query.startsWith("/")) { |
| 135 | const slashQuery = query.slice(1) |
| 136 | const results: ContextMenuQueryItem[] = [] |
| 137 | |
| 138 | // Add command suggestions first (prioritize commands at the top) |
| 139 | if (commands?.length) { |
| 140 | // Create searchable strings array for fzf |
| 141 | const searchableCommands = commands.map((command) => ({ |
| 142 | original: command, |
| 143 | searchStr: command.name, |
| 144 | })) |
| 145 | |
| 146 | // Initialize fzf instance for fuzzy search |
| 147 | const fzf = new Fzf(searchableCommands, { |
| 148 | selector: (item) => item.searchStr, |
| 149 | }) |
| 150 | |
| 151 | // Get fuzzy matching commands |
| 152 | const matchingCommands = slashQuery |
| 153 | ? fzf.find(slashQuery).map((result) => ({ |
| 154 | type: ContextMenuOptionType.Command, |
| 155 | value: result.item.original.name, |
| 156 | slashCommand: `/${result.item.original.name}`, |
| 157 | description: result.item.original.description, |
| 158 | argumentHint: result.item.original.argumentHint, |
| 159 | })) |
| 160 | : commands.map((command) => ({ |
| 161 | type: ContextMenuOptionType.Command, |
| 162 | value: command.name, |
| 163 | slashCommand: `/${command.name}`, |
| 164 | description: command.description, |
| 165 | argumentHint: command.argumentHint, |
| 166 | })) |
| 167 | |
| 168 | if (matchingCommands.length > 0) { |
| 169 | results.push({ |
| 170 | type: ContextMenuOptionType.SectionHeader, |
| 171 | label: "Commands", |
| 172 | }) |
| 173 | results.push(...matchingCommands) |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | // Add mode suggestions second |
| 178 | if (modes?.length) { |
| 179 | // Create searchable strings array for fzf |
| 180 | const searchableItems = modes.map((mode) => ({ |
| 181 | original: mode, |
no test coverage detected