mirror of https://github.com/helix-editor/helix
Use a fuzzy matcher for commands (#1386)
* Use a fuzzy matcher for commands * Take Clippy up on its suggestion * Rescope FUZZY_MATCHERpull/1399/head
parent
bd2ab5be43
commit
34db33e1dc
|
@ -26,6 +26,7 @@ use helix_view::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::{anyhow, bail, ensure, Context as _};
|
use anyhow::{anyhow, bail, ensure, Context as _};
|
||||||
|
use fuzzy_matcher::FuzzyMatcher;
|
||||||
use helix_lsp::{
|
use helix_lsp::{
|
||||||
block_on, lsp,
|
block_on, lsp,
|
||||||
util::{lsp_pos_to_pos, lsp_range_to_range, pos_to_lsp_pos, range_to_lsp_range},
|
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(),
|
":".into(),
|
||||||
Some(':'),
|
Some(':'),
|
||||||
|input: &str| {
|
|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
|
// we use .this over split_whitespace() because we care about empty segments
|
||||||
let parts = input.split(' ').collect::<Vec<&str>>();
|
let parts = input.split(' ').collect::<Vec<&str>>();
|
||||||
|
|
||||||
|
@ -3073,7 +3077,7 @@ fn command_mode(cx: &mut Context) {
|
||||||
let end = 0..;
|
let end = 0..;
|
||||||
cmd::TYPABLE_COMMAND_LIST
|
cmd::TYPABLE_COMMAND_LIST
|
||||||
.iter()
|
.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)))
|
.map(|command| (end.clone(), Cow::Borrowed(command.name)))
|
||||||
.collect()
|
.collect()
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue