Compare commits

..

No commits in common. "43a7196cf8df65e55414adceb6fca30ef740eae8" and "fd6ffc9645648e55e41d016863d6cae63731e83d" have entirely different histories.

6 changed files with 18 additions and 125 deletions

25
Cargo.lock generated
View File

@ -492,7 +492,6 @@ dependencies = [
"dirs",
"dotenv",
"gitea-rs",
"nucleo-matcher",
"octocrab",
"pretty_assertions",
"prost",
@ -906,16 +905,6 @@ dependencies = [
"winapi",
]
[[package]]
name = "nucleo-matcher"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf33f538733d1a5a3494b836ba913207f14d9d4a1d3cd67030c5061bdd2cac85"
dependencies = [
"memchr",
"unicode-segmentation",
]
[[package]]
name = "num-bigint"
version = "0.4.6"
@ -1145,9 +1134,9 @@ checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
[[package]]
name = "pretty_assertions"
version = "1.4.1"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ae130e2f271fbc2ac3a40fb1d07180839cdbbe443c7a27e1e3c13c5cac0116d"
checksum = "af7cee1a6c8a5b9208b3cb1061f10c0cb689087b3d8ce85fb9d2dd7a29b6ba66"
dependencies = [
"diff",
"yansi",
@ -1976,12 +1965,6 @@ dependencies = [
"tinyvec",
]
[[package]]
name = "unicode-segmentation"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493"
[[package]]
name = "untrusted"
version = "0.9.0"
@ -2346,9 +2329,9 @@ dependencies = [
[[package]]
name = "yansi"
version = "1.0.1"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049"
checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec"
[[package]]
name = "zeroize"

View File

@ -24,7 +24,6 @@ dirs = "5.0.1"
prost = "0.13.2"
prost-types = "0.13.2"
bytes = "1.7.1"
nucleo-matcher = "0.3.1"
[dev-dependencies]
pretty_assertions = "1.4.0"

View File

@ -1,12 +1,4 @@
use std::collections::BTreeMap;
use crate::{
app::App,
cache::CacheApp,
fuzzy_matcher::{FuzzyMatcher, FuzzyMatcherApp},
git_provider::Repository,
projects_list::ProjectsListApp,
};
use crate::{app::App, cache::CacheApp, projects_list::ProjectsListApp};
#[derive(Debug, Clone)]
pub struct RootCommand {
@ -18,7 +10,8 @@ impl RootCommand {
Self { app }
}
pub async fn execute(&mut self, search: Option<impl Into<String>>) -> anyhow::Result<()> {
#[tracing::instrument(skip(self))]
pub async fn execute(&mut self) -> anyhow::Result<()> {
tracing::debug!("executing");
let repositories = match self.app.cache().get().await? {
@ -32,19 +25,9 @@ impl RootCommand {
repositories
}
};
let needle = match search {
Some(needle) => needle.into(),
None => todo!(),
};
let matched_repos = self
.app
.fuzzy_matcher()
.match_repositories(&needle, &repositories);
let res = matched_repos.iter().take(10).rev().collect::<Vec<_>>();
for repo in res {
tracing::debug!("repo: {:?}", repo);
for repo in &repositories {
//tracing::info!("repo: {}", repo.to_rel_path().display());
}
tracing::info!("amount of repos fetched {}", repositories.len());
@ -52,43 +35,3 @@ impl RootCommand {
Ok(())
}
}
trait StringExt {
fn as_str_vec(&self) -> Vec<&str>;
}
impl StringExt for Vec<String> {
fn as_str_vec(&self) -> Vec<&str> {
self.iter().map(|r| r.as_ref()).collect()
}
}
impl StringExt for Vec<&String> {
fn as_str_vec(&self) -> Vec<&str> {
self.iter().map(|r| r.as_ref()).collect()
}
}
trait RepositoryMatcher {
fn match_repositories(&self, pattern: &str, repositories: &[Repository]) -> Vec<Repository>;
}
impl RepositoryMatcher for FuzzyMatcher {
fn match_repositories(&self, pattern: &str, repositories: &[Repository]) -> Vec<Repository> {
let haystack = repositories
.iter()
.map(|r| (r.to_rel_path().display().to_string(), r))
.collect::<BTreeMap<_, _>>();
let haystack_keys = haystack.keys().collect::<Vec<_>>();
let haystack_keys = haystack_keys.as_str_vec();
let res = self.match_pattern(pattern, &haystack_keys);
let matched_repos = res
.into_iter()
.filter_map(|repo_key| haystack.get(repo_key).map(|r| (*r).to_owned()))
.collect::<Vec<_>>();
matched_repos
}
}

View File

@ -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()
}
}

View File

@ -1,4 +1,10 @@
use octocrab::{models::Repository, params::repos::Sort, Octocrab, Page};
use anyhow::Context;
use octocrab::{
auth::Auth,
models::{hooks::Config, Repository},
params::repos::Sort,
NoSvc, Octocrab, Page,
};
use crate::{app::App, config::GitHubAccessToken};
@ -153,7 +159,7 @@ impl GitHubProvider {
fn get_client(
&self,
_url: Option<&String>,
url: Option<&String>,
access_token: &GitHubAccessToken,
) -> anyhow::Result<Octocrab> {
let client = octocrab::Octocrab::builder()

View File

@ -12,7 +12,6 @@ mod cache;
mod cache_codec;
mod commands;
mod config;
mod fuzzy_matcher;
mod git_provider;
mod projects_list;
@ -21,9 +20,6 @@ mod projects_list;
struct Command {
#[command(subcommand)]
command: Option<Commands>,
#[arg()]
search: Option<String>,
}
#[derive(Subcommand)]
@ -55,7 +51,7 @@ async fn main() -> anyhow::Result<()> {
match cli.command {
Some(_) => todo!(),
None => {
RootCommand::new(app).execute(cli.search.as_ref()).await?;
RootCommand::new(app).execute().await?;
}
}