From 38009c714cb633f2e1001aa3378dd119eaddc090 Mon Sep 17 00:00:00 2001 From: Bahex Date: Fri, 18 Jul 2025 05:16:55 +0300 Subject: [PATCH] feat(completion): enable nucleo's `prefer_prefix` option (#16183) cc: @blindFS @ysthakur # Description Enable `nucleo`'s `prefer_prefix` configuration option. Ranks suggestions with matches closer to the start higher than suggestions that have matches further from the start. Example: suggestions based on `reverse`:
Before After
``` bytes reverse polars reverse reverse str reverse ``` ``` reverse str reverse polars reverse bytes reverse ```
# User-Facing Changes More relevant suggestions with fuzzy matching algorithm. (`$env.config.completions.algorithm = "fuzzy"`) # Tests + Formatting We might want to add tests to make sure this option keeps working in the future. Co-authored-by: Bahex <17417311+Bahex@users.noreply.github.com> --- crates/nu-cli/src/completions/completion_options.rs | 6 +++++- crates/nu-lsp/src/symbols.rs | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/nu-cli/src/completions/completion_options.rs b/crates/nu-cli/src/completions/completion_options.rs index 7022d7988d..493f30d341 100644 --- a/crates/nu-cli/src/completions/completion_options.rs +++ b/crates/nu-cli/src/completions/completion_options.rs @@ -102,7 +102,11 @@ impl NuMatcher<'_, T> { options, needle: needle.to_owned(), state: State::Fuzzy { - matcher: Matcher::new(Config::DEFAULT), + matcher: Matcher::new({ + let mut cfg = Config::DEFAULT; + cfg.prefer_prefix = true; + cfg + }), atom, items: Vec::new(), }, diff --git a/crates/nu-lsp/src/symbols.rs b/crates/nu-lsp/src/symbols.rs index bea7bab3e8..07b01d2028 100644 --- a/crates/nu-lsp/src/symbols.rs +++ b/crates/nu-lsp/src/symbols.rs @@ -80,7 +80,11 @@ pub(crate) struct SymbolCache { impl SymbolCache { pub fn new() -> Self { SymbolCache { - matcher: Matcher::new(Config::DEFAULT), + matcher: Matcher::new({ + let mut cfg = Config::DEFAULT; + cfg.prefer_prefix = true; + cfg + }), cache: BTreeMap::new(), dirty_flags: BTreeMap::new(), }