Compare commits
No commits in common. "37ae70bc56146cbe687b239ae27fb904acfbf5b9" and "ff8103c8050074f223b297678b8560c9a7f59d11" have entirely different histories.
37ae70bc56
...
ff8103c805
@ -1,8 +1,6 @@
|
|||||||
use nucleo_matcher::{pattern::Pattern, Matcher, Utf32Str};
|
use nucleo_matcher::{pattern::Pattern, Matcher, Utf32Str};
|
||||||
|
|
||||||
use crate::{
|
use crate::{app::App, cache::CacheApp, projects_list::ProjectsListApp};
|
||||||
app::App, cache::CacheApp, fuzzy_matcher::FuzzyMatcherApp, projects_list::ProjectsListApp,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct RootCommand {
|
pub struct RootCommand {
|
||||||
@ -28,23 +26,28 @@ impl RootCommand {
|
|||||||
repositories
|
repositories
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let haystack = repositories
|
||||||
|
.iter()
|
||||||
|
.map(|r| r.to_rel_path().display().to_string());
|
||||||
|
|
||||||
let needle = match search {
|
let needle = match search {
|
||||||
Some(needle) => needle.into(),
|
Some(needle) => needle.into(),
|
||||||
None => todo!(),
|
None => todo!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let haystack = repositories
|
let pattern = Pattern::new(
|
||||||
.iter()
|
&needle,
|
||||||
.map(|r| r.to_rel_path().display().to_string())
|
nucleo_matcher::pattern::CaseMatching::Ignore,
|
||||||
.collect::<Vec<_>>();
|
nucleo_matcher::pattern::Normalization::Smart,
|
||||||
|
nucleo_matcher::pattern::AtomKind::Fuzzy,
|
||||||
let haystack = haystack.as_str_vec();
|
);
|
||||||
|
let mut matcher = Matcher::new(nucleo_matcher::Config::DEFAULT);
|
||||||
let res = self.app.fuzzy_matcher().match_pattern(&needle, &haystack);
|
let res = pattern.match_list(haystack, &mut matcher);
|
||||||
|
|
||||||
let res = res.iter().take(10).rev().collect::<Vec<_>>();
|
let res = res.iter().take(10).rev().collect::<Vec<_>>();
|
||||||
|
|
||||||
for repo in res {
|
for (repo, _score) in res {
|
||||||
tracing::debug!("repo: {:?}", repo);
|
tracing::debug!("repo: {:?}", repo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,13 +56,3 @@ impl RootCommand {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trait StringExt {
|
|
||||||
fn as_str_vec<'a>(&'a self) -> Vec<&'a str>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl StringExt for Vec<String> {
|
|
||||||
fn as_str_vec<'a>(&'a self) -> Vec<&'a str> {
|
|
||||||
self.iter().map(|r| r.as_ref()).collect()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
use nucleo_matcher::{pattern::Pattern, Matcher};
|
|
||||||
|
|
||||||
use crate::app::App;
|
|
||||||
|
|
||||||
pub struct FuzzyMatcher {}
|
|
||||||
|
|
||||||
impl FuzzyMatcher {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self {}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn match_pattern<'a>(&self, pattern: &'a str, items: &'a [&'a str]) -> Vec<&'a str> {
|
|
||||||
let pat = Pattern::new(
|
|
||||||
&pattern,
|
|
||||||
nucleo_matcher::pattern::CaseMatching::Ignore,
|
|
||||||
nucleo_matcher::pattern::Normalization::Smart,
|
|
||||||
nucleo_matcher::pattern::AtomKind::Fuzzy,
|
|
||||||
);
|
|
||||||
let mut matcher = Matcher::new(nucleo_matcher::Config::DEFAULT);
|
|
||||||
let res = pat.match_list(items, &mut matcher);
|
|
||||||
|
|
||||||
res.into_iter().map(|((item, _))| *item).collect::<Vec<_>>()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait FuzzyMatcherApp {
|
|
||||||
fn fuzzy_matcher(&self) -> FuzzyMatcher;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FuzzyMatcherApp for &'static App {
|
|
||||||
fn fuzzy_matcher(&self) -> FuzzyMatcher {
|
|
||||||
FuzzyMatcher::new()
|
|
||||||
}
|
|
||||||
}
|
|
@ -12,7 +12,6 @@ mod cache;
|
|||||||
mod cache_codec;
|
mod cache_codec;
|
||||||
mod commands;
|
mod commands;
|
||||||
mod config;
|
mod config;
|
||||||
mod fuzzy_matcher;
|
|
||||||
mod git_provider;
|
mod git_provider;
|
||||||
mod projects_list;
|
mod projects_list;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user