From 4ebfc418522966bc58e49966d5152ecbcbf20010 Mon Sep 17 00:00:00 2001 From: Stuart Hinson Date: Mon, 27 Dec 2021 13:29:07 -0500 Subject: [PATCH 1/3] Use a fuzzy matcher for commands --- helix-term/src/commands.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 16a2cf3517c1..89c0d9544fb7 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -26,6 +26,7 @@ use helix_view::{ }; use anyhow::{anyhow, bail, ensure, Context as _}; +use fuzzy_matcher::FuzzyMatcher; use helix_lsp::{ block_on, lsp, util::{lsp_pos_to_pos, lsp_range_to_range, pos_to_lsp_pos, range_to_lsp_range}, @@ -3044,6 +3045,9 @@ pub mod cmd { }); } +static FUZZY_MATCHER: Lazy = + Lazy::new(|| fuzzy_matcher::skim::SkimMatcherV2::default()); + fn command_mode(cx: &mut Context) { let mut prompt = Prompt::new( ":".into(), @@ -3058,7 +3062,7 @@ fn command_mode(cx: &mut Context) { let end = 0..; cmd::TYPABLE_COMMAND_LIST .iter() - .filter(|command| command.name.contains(input)) + .filter(|command| FUZZY_MATCHER.fuzzy_match(command.name, input).is_some()) .map(|command| (end.clone(), Cow::Borrowed(command.name))) .collect() } else { From 2136764323b80224984ffbe0fef8ee243956c2a9 Mon Sep 17 00:00:00 2001 From: Stuart Hinson Date: Mon, 27 Dec 2021 13:35:58 -0500 Subject: [PATCH 2/3] Take Clippy up on its suggestion --- helix-term/src/commands.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 89c0d9544fb7..a8e2097da5e3 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -3046,7 +3046,7 @@ pub mod cmd { } static FUZZY_MATCHER: Lazy = - Lazy::new(|| fuzzy_matcher::skim::SkimMatcherV2::default()); + Lazy::new(fuzzy_matcher::skim::SkimMatcherV2::default); fn command_mode(cx: &mut Context) { let mut prompt = Prompt::new( From feb77b99ed2bea928da9266527a393f3fffd4772 Mon Sep 17 00:00:00 2001 From: Stuart Hinson Date: Tue, 28 Dec 2021 07:08:41 -0500 Subject: [PATCH 3/3] Rescope FUZZY_MATCHER --- helix-term/src/commands.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index a8e2097da5e3..fc479476300e 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -3045,14 +3045,14 @@ pub mod cmd { }); } -static FUZZY_MATCHER: Lazy = - Lazy::new(fuzzy_matcher::skim::SkimMatcherV2::default); - fn command_mode(cx: &mut Context) { let mut prompt = Prompt::new( ":".into(), Some(':'), |input: &str| { + static FUZZY_MATCHER: Lazy = + Lazy::new(fuzzy_matcher::skim::SkimMatcherV2::default); + // we use .this over split_whitespace() because we care about empty segments let parts = input.split(' ').collect::>();