Skip to content

Commit

Permalink
Use a fuzzy matcher for commands (#1386)
Browse files Browse the repository at this point in the history
* Use a fuzzy matcher for commands

* Take Clippy up on its suggestion

* Rescope FUZZY_MATCHER
  • Loading branch information
stuarth authored Dec 29, 2021
1 parent bd2ab5b commit 34db33e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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>>();

Expand All @@ -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 {
Expand Down

0 comments on commit 34db33e

Please sign in to comment.