From 7567478754bfbc4b103b692c6b1574f80a8b453f Mon Sep 17 00:00:00 2001 From: sigoden Date: Thu, 23 Jan 2025 09:46:25 +0800 Subject: refactor: sort repl autocompletion items by fuzzy-match score (#1119) --- src/config/mod.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/config/mod.rs') diff --git a/src/config/mod.rs b/src/config/mod.rs index 98bcab3..ec6a930 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1850,10 +1850,15 @@ impl Config { } values.extend(complete_agent_variables(args[0])); }; - values + let mut values_with_score: Vec<_> = values .into_iter() - .filter(|(value, _)| fuzzy_match(value, filter)) - .collect() + .filter_map(|v| { + let score = fuzzy_match(&v.0, filter)?; + Some((v, score)) + }) + .collect(); + values_with_score.sort_unstable_by(|a, b| b.1.cmp(&a.1)); + values_with_score.into_iter().map(|v| v.0).collect() } pub fn sync_models_url(&self) -> String { -- cgit v1.2.3