Skip to content

Commit 89061b8

Browse files
committed
transition to nucleo for fuzzy matching
1 parent bc73740 commit 89061b8

File tree

15 files changed

+763
-982
lines changed

15 files changed

+763
-982
lines changed

Cargo.lock

Lines changed: 103 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

helix-core/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ chrono = { version = "0.4", default-features = false, features = ["alloc", "std"
4848
etcetera = "0.8"
4949
textwrap = "0.16.0"
5050

51+
nucleo = { version = "0.1", git = "https://github.com/helix-editor/nucleo.git" }
52+
parking_lot = "0.12"
53+
5154
[dev-dependencies]
5255
quickcheck = { version = "1", default-features = false }
5356
indoc = "2.0.3"

helix-core/src/fuzzy.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use nucleo::{CaseMatching, MatcherConfig};
2+
use parking_lot::Mutex;
3+
4+
pub static MATCHER: Mutex<Option<nucleo::Matcher>> = Mutex::new(None);
5+
6+
/// convenicne function to easily fuzzy match
7+
/// on a (relatievly small list of inputs). This is not recommended for building a full tui
8+
/// application that can match large numbers of matches as all matching is done on the current
9+
/// thread, effectively blocking the UI
10+
pub fn fuzzy_match<T: AsRef<str>>(
11+
pattern: &str,
12+
items: impl IntoIterator<Item = T>,
13+
path: bool,
14+
) -> Vec<(T, u32)> {
15+
let mut matcher_lock = MATCHER.lock();
16+
let matcher = matcher_lock.get_or_insert_with(nucleo::Matcher::default);
17+
matcher.config = MatcherConfig::DEFAULT;
18+
if path {
19+
matcher.config.set_match_paths();
20+
}
21+
nucleo::fuzzy_match(matcher, pattern, items, CaseMatching::Smart)
22+
}

helix-core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub mod config;
77
pub mod diagnostic;
88
pub mod diff;
99
pub mod doc_formatter;
10+
pub mod fuzzy;
1011
pub mod graphemes;
1112
pub mod history;
1213
pub mod increment;

helix-term/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ chrono = { version = "0.4", default-features = false, features = ["clock"] }
4949
log = "0.4"
5050

5151
# File picker
52-
fuzzy-matcher = "0.3"
52+
nucleo = { version = "0.1", git = "https://github.com/helix-editor/nucleo.git" }
5353
ignore = "0.4"
5454
# markdown doc rendering
5555
pulldown-cmark = { version = "0.9", default-features = false }

helix-term/src/application.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,11 @@ impl Application {
166166
if first.is_dir() {
167167
helix_loader::set_current_working_dir(first.clone())?;
168168
editor.new_file(Action::VerticalSplit);
169-
let picker = ui::file_picker(".".into(), &config.load().editor);
169+
let picker = ui::file_picker(
170+
".".into(),
171+
&config.load().editor,
172+
editor.redraw_handle.0.clone(),
173+
);
170174
compositor.push(Box::new(overlaid(picker)));
171175
} else {
172176
let nr_of_files = args.files.len();

0 commit comments

Comments
 (0)