A simple CPU rendered GUI IDE experience.
Diffstat (limited to 'src/com.rs')
| -rw-r--r-- | src/com.rs | 62 |
1 files changed, 1 insertions, 61 deletions
@@ -48,71 +48,11 @@ impl<'a> Key<'a> for &'a CompletionItem { } } - -pub fn score<'a, T: 'a + ?Sized>( - x: impl Iterator<Item = &'a T>, - f: impl Fn(&'a T) -> &'a str, - filter: &'_ str, -) -> Vec<(u32, &'a T, Vec<u32>)> { - #[thread_local] - static mut MATCHER: LazyLock<nucleo::Matcher> = - LazyLock::new(|| nucleo::Matcher::new(nucleo::Config::DEFAULT)); - - let p = nucleo::pattern::Pattern::parse( - filter, - nucleo::pattern::CaseMatching::Smart, - nucleo::pattern::Normalization::Smart, - ); - let mut v = x - .map(move |y| { - let mut utf32 = vec![]; - // std::env::args().nth(1).unwrap().as_bytes().fi .fold(0, |acc, x| acc * 10 + x - b'0'); - let hay = f(y); - let mut indices = vec![]; - let score = p - .indices( - nucleo::Utf32Str::new(hay, &mut utf32), - unsafe { &mut *MATCHER }, - &mut indices, - ) - .unwrap_or(0); - indices.sort_unstable(); - indices.dedup(); - - (score, y, indices) - }) - .collect::<Vec<_>>(); - // std::fs::write( - // "com", - // v.iter().map(|x| x.1.label.clone() + "\n").collect::<String>(), - // ); - v.sort_by_key(|x| Reverse(x.0)); - v -} - -fn com_as_str(y: &CompletionItem) -> &str { - y.filter_text.as_deref().unwrap_or(&y.label) -} fn score_c<'a>( x: impl Iterator<Item = &'a CompletionItem>, filter: &'_ str, ) -> Vec<(u32, &'a CompletionItem, Vec<u32>)> { - score(x, com_as_str, filter) -} - -pub fn filter<'a, T: 'a + ?Sized>( - i: impl Iterator<Item = &'a T>, - f: impl Fn(&'a T) -> &'a str, - filter: &'_ str, -) -> impl Iterator<Item = &'a T> { - i.filter(move |y| { - filter.is_empty() - || f(y).chars().any(|x| filter.chars().contains(&x)) - // .collect::<HashSet<_>>() - // .intersection(&filter.chars().collect()) - // .count() - // > 0 - }) + score(x, filter) } fn filter_c<'a>( |