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 1 commit
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
59 changes: 39 additions & 20 deletions 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 @@ -34,12 +34,12 @@ 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 }
itertools = "0.11"
log = "0.4"
notify = "5.1"
notify-debouncer-mini = "0.2"
nucleo = "0.1"
once_cell = "1"
ratatui = { version = "0.21", default-features = false, features = ['crossterm', 'serde'] }
rayon-core = "1.11"
Expand Down
37 changes: 30 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,7 @@ pub struct FuzzyFindPopup {
filtered: Vec<(usize, Vec<usize>)>,
key_config: SharedKeyConfig,
target: Option<FuzzyFinderTarget>,
matcher: Matcher,
}

impl FuzzyFindPopup {
Expand Down Expand Up @@ -65,6 +66,7 @@ impl FuzzyFindPopup {
key_config,
selection: 0,
target: None,
matcher: Matcher::default(),
}
}

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

if let Some(q) = &self.query {
let matcher =
fuzzy_matcher::skim::SkimMatcherV2::default();
let mut line_content_buf = Vec::new();
Copy link
Owner

Choose a reason for hiding this comment

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

maybe we should also cache these buffers, right?

Copy link
Owner

Choose a reason for hiding this comment

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

maybe just wipe them as soon as one closes the window?

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for the review! I moved them to the FuzzyFindPopup alongside the matcher. Maybe I should move matcher and matcher_* to a new struct to omit this prefix?

let mut query_buf = Vec::new();
let query = Utf32Str::new(q, &mut query_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 line_content_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