aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
authorStuart Hinson2021-12-29 09:18:17 +0000
committerGitHub2021-12-29 09:18:17 +0000
commit34db33e1dcbb845134f36f90695799a2de472e35 (patch)
treec81ce17721153a029aa7eda9b60f994deb2364ee /helix-term/src
parentbd2ab5be4331a2ab6d406378a9c0868eb2f72819 (diff)
Use a fuzzy matcher for commands (#1386)
* Use a fuzzy matcher for commands * Take Clippy up on its suggestion * Rescope FUZZY_MATCHER
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/commands.rs6
1 files changed, 5 insertions, 1 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 9c1650b8..139e7ceb 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},
@@ -3064,6 +3065,9 @@ fn command_mode(cx: &mut Context) {
":".into(),
Some(':'),
|input: &str| {
+ static FUZZY_MATCHER: Lazy<fuzzy_matcher::skim::SkimMatcherV2> =
+ Lazy::new(fuzzy_matcher::skim::SkimMatcherV2::default);
+
// we use .this over split_whitespace() because we care about empty segments
let parts = input.split(' ').collect::<Vec<&str>>();
@@ -3073,7 +3077,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 {