A simple CPU rendered GUI IDE experience.
fix rebase issues
| -rw-r--r-- | src/com.rs | 62 | ||||
| -rw-r--r-- | src/commands.rs | 21 | ||||
| -rw-r--r-- | src/edi/st.rs | 6 | ||||
| -rw-r--r-- | src/rnd.rs | 3 |
4 files changed, 15 insertions, 77 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>( diff --git a/src/commands.rs b/src/commands.rs index 4f19b01..05135cb 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -4,11 +4,10 @@ use std::path::Path; use Default::default; use dsb::Cell; use dsb::cell::Style; -use lsp_types::*; use crate::FG; -use crate::com::{back, filter, next, score}; -use crate::text::{TextArea, col, color_, set_a}; +use crate::menu::{back, filter, next, score}; +use crate::text::{TextArea, col, color_}; const COMMANDS: [(&str, &str); 3] = [ ("w", "Write / Save"), @@ -103,17 +102,19 @@ fn score_c<'a>( x: impl Iterator<Item = &'a str>, filter: &'_ str, ) -> Vec<(u32, &'a str, Vec<u32>)> { - score(x, std::convert::identity, filter) + score(x, filter) } fn filter_c<'a>( - completion: &'a Commands, + _me: &'a Commands, f: &'_ str, ) -> impl Iterator<Item = &'a str> { - filter(COMMANDS.into_iter().map(|(x, _)| x), std::convert::identity, f) + filter(COMMANDS.into_iter().map(|(x, _)| x), f) } -fn sym_as_str(x: &str) -> &str { - &x +impl<'a> crate::menu::Key<'a> for &'a str { + fn key(&self) -> impl Into<std::borrow::Cow<'a, str>> { + *self + } } fn charc(c: &str) -> usize { c.chars().count() @@ -121,7 +122,7 @@ fn charc(c: &str) -> usize { #[implicit_fn::implicit_fn] fn r( x: &str, - workspace: &Path, + _workspace: &Path, c: usize, selected: bool, indices: &[u32], @@ -138,7 +139,7 @@ fn r( }); let i = &mut b[2..]; let qualifier = COMMANDS.iter().find(|y| y.0 == x).unwrap().1.chars(); - let left = i.len() as i32 + let _left = i.len() as i32 - (charc(&x) as i32 + qualifier.clone().count() as i32) - 3; diff --git a/src/edi/st.rs b/src/edi/st.rs index 4556035..3186b05 100644 --- a/src/edi/st.rs +++ b/src/edi/st.rs @@ -9,8 +9,8 @@ use winit::keyboard::{Key, NamedKey, SmolStr}; use crate::commands::Commands; use crate::edi::handle2; -use crate::lsp::{AQErr, RequestError, Rq, RqS}; -use crate::sym::{Symbols, SymbolsType}; +use crate::lsp::{AQErr, Rq, RqS}; +use crate::sym::{Symbols, SymbolsList}; use crate::text::TextArea; use crate::{ BoolRequest, CLICKING, InputRequest, act, alt, ctrl, handle, shift, @@ -67,7 +67,7 @@ Command(t) => K(_) => _, SpaceMode => K(Key::Named(Escape)) => Normal, SpaceMode => K(Key::Character(x) if x == "f") => _ [Symbols], SpaceMode => K(Key::Character(x) if x == "a") => _ [CodeAction], -SpaceMode => K(Key::Character(x) if x == "c") => _ [Comment(Range<usize> => 0..0)], +SpaceMode => K(Key::Character(x) if x == "c") => _ [Comment(Self::SpaceMode)], SpaceMode => C(_) => _, SpaceMode => M(_) => _, SpaceMode => K(_) => _, @@ -917,9 +917,6 @@ pub fn render( draw_at(x, y, &image); } - if matches!(ed.state, State::Default | State::Selection(_) | State::Insert) { - draw_at(x, y, &cursor); - } window.pre_present_notify(); let buffer = surface.buffer_mut().unwrap(); let x = unsafe { |