Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-core/src/fuzzy.rs')
| -rw-r--r-- | helix-core/src/fuzzy.rs | 49 |
1 files changed, 0 insertions, 49 deletions
diff --git a/helix-core/src/fuzzy.rs b/helix-core/src/fuzzy.rs deleted file mode 100644 index da46518f..00000000 --- a/helix-core/src/fuzzy.rs +++ /dev/null @@ -1,49 +0,0 @@ -use std::ops::DerefMut; - -use nucleo::pattern::{Atom, AtomKind, CaseMatching, Normalization}; -use nucleo::Config; -use parking_lot::Mutex; - -pub struct LazyMutex<T> { - inner: Mutex<Option<T>>, - init: fn() -> T, -} - -impl<T> LazyMutex<T> { - pub const fn new(init: fn() -> T) -> Self { - Self { - inner: Mutex::new(None), - init, - } - } - - pub fn lock(&self) -> impl DerefMut<Target = T> + '_ { - parking_lot::MutexGuard::map(self.inner.lock(), |val| val.get_or_insert_with(self.init)) - } -} - -pub static MATCHER: LazyMutex<nucleo::Matcher> = LazyMutex::new(nucleo::Matcher::default); - -/// convenience function to easily fuzzy match -/// on a (relatively 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, u16)> { - let mut matcher = MATCHER.lock(); - matcher.config = Config::DEFAULT; - if path { - matcher.config.set_match_paths(); - } - let pattern = Atom::new( - pattern, - CaseMatching::Smart, - Normalization::Smart, - AtomKind::Fuzzy, - false, - ); - pattern.match_list(items, &mut matcher) -} |