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 nucleo instead of fuzzy-matcher #1830

Closed
Closed
Show file tree
Hide file tree
Changes from all 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
40 changes: 39 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ crossterm = { version = "0.26.1", features = ["serde"] }
dirs = "5.0"
easy-cast = "0.5"
filetreelist = { path = "./filetreelist", version = "0.5" }
fuzzy-matcher = "0.3"
gh-emoji = { version = "1.0", optional = true }
indexmap = "1.9"
itertools = "0.11"
log = "0.4"
notify = "5.1"
notify-debouncer-mini = "0.2"
nucleo = "0.2"
once_cell = "1"
ratatui = { version = "0.21", default-features = false, features = ['crossterm', 'serde'] }
rayon-core = "1.11"
Expand Down
40 changes: 33 additions & 7 deletions src/components/fuzzy_find_popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
};
use anyhow::Result;
use crossterm::event::Event;
use fuzzy_matcher::FuzzyMatcher;
use nucleo::{Matcher, Utf32Str};
use ratatui::{
backend::Backend,
layout::{Constraint, Direction, Layout, Margin, Rect},
Expand All @@ -35,6 +35,9 @@ pub struct FuzzyFindPopup {
filtered: Vec<(usize, Vec<usize>)>,
key_config: SharedKeyConfig,
target: Option<FuzzyFinderTarget>,
matcher: Matcher,
matcher_haystack_buf: Vec<char>,
matcher_needle_buf: Vec<char>,
}

impl FuzzyFindPopup {
Expand Down Expand Up @@ -65,6 +68,9 @@ impl FuzzyFindPopup {
key_config,
selection: 0,
target: None,
matcher: Matcher::default(),
matcher_haystack_buf: Vec::new(),
matcher_needle_buf: Vec::new(),
}
}

Expand All @@ -88,17 +94,37 @@ impl FuzzyFindPopup {
self.filtered.clear();

if let Some(q) = &self.query {
let matcher =
fuzzy_matcher::skim::SkimMatcherV2::default();
let query =
Utf32Str::new(q, &mut self.matcher_needle_buf);
let mut matched_indicies = Vec::new();

let mut contents = self
.contents
.iter()
.enumerate()
.filter_map(|a| {
matcher
.fuzzy_indices(a.1, q)
.map(|(score, indices)| (score, a.0, indices))
.filter_map(|(index, line_content)| {
matched_indicies.clear();
self.matcher
.fuzzy_indices(
Utf32Str::new(
line_content,
&mut self.matcher_haystack_buf,
),
query,
&mut matched_indicies,
)
.map(|score| {
(
score,
index,
matched_indicies
.iter()
.filter_map(|a| {
(*a).try_into().ok()
})
.collect(),
)
})
})
.collect::<Vec<(_, _, _)>>();

Expand Down
Loading