MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / search

Method search

crates/opencode-tui/src/command.rs:494–521  ·  view source on GitHub ↗
(&self, query: &str)

Source from the content-addressed store, hash-verified

492 }
493
494 pub fn search(&self, query: &str) -> Vec<&SlashCommand> {
495 let mut scored: Vec<(&SlashCommand, i32)> = self
496 .commands
497 .values()
498 .filter_map(|cmd| {
499 let name_score = fuzzy_match(query, &cmd.name);
500 let alias_score = cmd
501 .aliases
502 .iter()
503 .filter_map(|a| fuzzy_match(query, a))
504 .max();
505 let title_score = fuzzy_match(query, &cmd.title);
506 let best = name_score
507 .into_iter()
508 .chain(alias_score)
509 .chain(title_score)
510 .max();
511 best.map(|s| (cmd, s))
512 })
513 .collect();
514
515 scored.sort_by(|a, b| {
516 b.1.cmp(&a.1)
517 .then_with(|| b.0.suggested.cmp(&a.0.suggested))
518 });
519
520 scored.into_iter().map(|(cmd, _)| cmd).collect()
521 }
522
523 pub fn get_by_category(&self, category: &CommandCategory) -> Vec<&SlashCommand> {
524 self.by_category

Callers 2

recompute_suggestionsMethod · 0.45
refresh_filterMethod · 0.45

Calls 1

fuzzy_matchFunction · 0.70

Tested by

no test coverage detected