Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a fuzzy matcher for commands #1386

Merged
merged 3 commits into from
Dec 29, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -3044,6 +3045,9 @@ pub mod cmd {
});
}

static FUZZY_MATCHER: Lazy<fuzzy_matcher::skim::SkimMatcherV2> =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: Since this is only used inside fn command_mode I'd move the definition inside the fn body, that way it's scoped to the command.

Lazy::new(fuzzy_matcher::skim::SkimMatcherV2::default);

fn command_mode(cx: &mut Context) {
let mut prompt = Prompt::new(
":".into(),
Expand All @@ -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 {
Expand Down