Score a command against a search query (higher = better)
(cmd: Command, query: string)
| 23 | |
| 24 | /** Score a command against a search query (higher = better) */ |
| 25 | function score(cmd: Command, query: string): number { |
| 26 | const q = query.toLowerCase(); |
| 27 | const label = cmd.label.toLowerCase(); |
| 28 | if (label === q) return 100; |
| 29 | if (label.startsWith(q)) return 80; |
| 30 | if (label.includes(q)) return 60; |
| 31 | if (cmd.description.toLowerCase().includes(q)) return 40; |
| 32 | if (fuzzyMatch(label, q)) return 20; |
| 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | interface GroupedResults { |
| 37 | label: string; |
no test coverage detected