on master help sign in
Use a fuzzy matcher for commands (#1386)

* Use a fuzzy matcher for commands * Take Clippy up on its suggestion * Rescope FUZZY_MATCHER

commit34db33e1dcbb845134f36f90695799a2de472e35 authorStuart Hinson <stuart.hinson@gmail.com> dateWed 29 Dec 2021, 04:18 (5 years ago) parentbd2ab5b
1 file changed+5−1
helix-term/src/commands.rs+5−1
helix-term/src/commands.rs+5−1
@@ -26,6 +26,7 @@ use helix_view::{
2626};
2727
2828use anyhow::{anyhow, bail, ensure, Context as _};
29+use fuzzy_matcher::FuzzyMatcher;
2930use helix_lsp::{
3031 block_on, lsp,
3132 util::{lsp_pos_to_pos, lsp_range_to_range, pos_to_lsp_pos, range_to_lsp_range},
@@ -3064,6 +3065,9 @@ fn command_mode(cx: &mut Context) {
30643065 ":".into(),
30653066 Some(':'),
30663067 |input: &str| {
3068+ static FUZZY_MATCHER: Lazy<fuzzy_matcher::skim::SkimMatcherV2> =
3069+ Lazy::new(fuzzy_matcher::skim::SkimMatcherV2::default);
3070+
30673071 // we use .this over split_whitespace() because we care about empty segments
30683072 let parts = input.split(' ').collect::<Vec<&str>>();
30693073
@@ -3073,7 +3077,7 @@ fn command_mode(cx: &mut Context) {
30733077 let end = 0..;
30743078 cmd::TYPABLE_COMMAND_LIST
30753079 .iter()
3076− .filter(|command| command.name.contains(input))
3080+ .filter(|command| FUZZY_MATCHER.fuzzy_match(command.name, input).is_some())
30773081 .map(|command| (end.clone(), Cow::Borrowed(command.name)))
30783082 .collect()
30793083 } else {