Skip to content

Commit

Permalink
transition to nucleo for fuzzy matching
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalkuthe committed Aug 3, 2023
1 parent bc73740 commit 844f5d4
Show file tree
Hide file tree
Showing 15 changed files with 761 additions and 982 deletions.
111 changes: 101 additions & 10 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions helix-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ chrono = { version = "0.4", default-features = false, features = ["alloc", "std"
etcetera = "0.8"
textwrap = "0.16.0"

nucleo = { version = "0.1", git = "https://github.com/helix-editor/nucleo.git" }
parking_lot = "0.12"

[dev-dependencies]
quickcheck = { version = "1", default-features = false }
indoc = "2.0.3"
22 changes: 22 additions & 0 deletions helix-core/src/fuzzy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use nucleo::{CaseMatching, MatcherConfig};
use parking_lot::Mutex;

pub static MATCHER: Mutex<Option<nucleo::Matcher>> = Mutex::new(None);

/// convenicne function to easily fuzzy match
/// on a (relatievly small list of inputs). This is not recommended for building a full tui
/// application that can match large numbers of matches as all matching is done on the current
/// thread, effectively blocking the UI
pub fn fuzzy_match<T: AsRef<str>>(
pattern: &str,
items: impl IntoIterator<Item = T>,
path: bool,
) -> Vec<(T, u32)> {
let mut matcher_lock = MATCHER.lock();
let matcher = matcher_lock.get_or_insert_with(nucleo::Matcher::default);
matcher.config = MatcherConfig::DEFAULT;
if path {
matcher.config.set_match_paths();
}
nucleo::fuzzy_match(matcher, pattern, items, CaseMatching::Smart)
}
1 change: 1 addition & 0 deletions helix-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod config;
pub mod diagnostic;
pub mod diff;
pub mod doc_formatter;
pub mod fuzzy;
pub mod graphemes;
pub mod history;
pub mod increment;
Expand Down
2 changes: 1 addition & 1 deletion helix-term/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ chrono = { version = "0.4", default-features = false, features = ["clock"] }
log = "0.4"

# File picker
fuzzy-matcher = "0.3"
nucleo = { version = "0.1", git = "https://github.com/helix-editor/nucleo.git" }
ignore = "0.4"
# markdown doc rendering
pulldown-cmark = { version = "0.9", default-features = false }
Expand Down
6 changes: 5 additions & 1 deletion helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ impl Application {
if first.is_dir() {
helix_loader::set_current_working_dir(first.clone())?;
editor.new_file(Action::VerticalSplit);
let picker = ui::file_picker(".".into(), &config.load().editor);
let picker = ui::file_picker(
".".into(),
&config.load().editor,
editor.redraw_handle.0.clone(),
);
compositor.push(Box::new(overlaid(picker)));
} else {
let nr_of_files = args.files.len();
Expand Down
Loading

0 comments on commit 844f5d4

Please sign in to comment.