A simple CPU rendered GUI IDE experience.
Diffstat (limited to 'src/sym.rs')
-rw-r--r--src/sym.rs166
1 files changed, 121 insertions, 45 deletions
diff --git a/src/sym.rs b/src/sym.rs
index 1a0db44..327e3e7 100644
--- a/src/sym.rs
+++ b/src/sym.rs
@@ -9,50 +9,18 @@ use itern::Iter3;
use lsp_types::*;
use crate::FG;
-use crate::menu::generic::{GenericMenu, MenuData};
-use crate::menu::{Key, charc};
-use crate::text::{col, color_, set_a};
-pub enum Symb {}
-impl MenuData for Symb {
- type Data = (SymbolsList, Vec<SymbolInformation>, SymbolsType);
+use crate::menu::{Key, back, filter, next, score};
+use crate::text::{TextArea, col, color_, set_a};
- type Element<'a> = UsedSI<'a>;
-
- fn gn(
- (r, tree, _): &Self::Data,
- ) -> impl Iterator<Item = Self::Element<'_>> {
- match r {
- SymbolsList::Document(DocumentSymbolResponse::Flat(x)) =>
- Iter3::A(x.iter().map(UsedSI::from)),
- SymbolsList::Document(DocumentSymbolResponse::Nested(x)) =>
- Iter3::B(x.iter().flat_map(|x| gen move {
- let mut q = VecDeque::with_capacity(12);
- q.push_back(x);
- while let Some(x) = q.pop_front() {
- q.extend(x.children.iter().flatten());
- yield x.into();
- }
- })),
- SymbolsList::Workspace(WorkspaceSymbolResponse::Flat(x)) =>
- Iter3::C(chain(tree, x.iter()).map(UsedSI::from)),
- _ => unreachable!("please no"),
- }
- }
-
- fn r(
- &(.., sty): &Self::Data,
- x: Self::Element<'_>,
- workspace: &Path,
- c: usize,
- selected: bool,
- indices: &[u32],
- to: &mut Vec<Cell>,
- ) {
- r(x, workspace, c, selected, indices, to, sty)
- }
+#[derive(Debug, Default)]
+pub struct Symbols {
+ pub r: SymbolsList,
+ pub tree: Vec<SymbolInformation>,
+ pub tedit: TextArea,
+ pub selection: usize,
+ pub vo: usize,
+ pub ty: SymbolsType,
}
-pub type Symbols = GenericMenu<Symb>;
-
#[derive(Debug, Eq, PartialEq, Clone, Copy)]
pub enum GoTo<'a> {
Loc(&'a Location),
@@ -124,8 +92,8 @@ impl Default for SymbolsList {
Self::Workspace(WorkspaceSymbolResponse::Flat(vec![]))
}
}
-
-impl GenericMenu<Symb> {
+const N: usize = 30;
+impl Symbols {
pub fn new(tree: &[PathBuf]) -> Self {
let tree = tree
.iter()
@@ -145,7 +113,80 @@ impl GenericMenu<Symb> {
tags: None,
})
.collect();
- Self { data: (default(), tree, default()), ..default() }
+ Self { tree, ..Default::default() }
+ }
+ fn f(&self) -> String {
+ self.tedit.rope.to_string()
+ }
+ pub fn next(&mut self) {
+ let n = filter_c(self, &self.f()).count();
+ // coz its bottom up
+ back::<N>(n, &mut self.selection, &mut self.vo);
+ }
+
+ pub fn sel(&self) -> UsedSI<'_> {
+ let f = self.f();
+ score_c(filter_c(self, &f), &f)[self.selection].1
+ }
+
+ pub fn back(&mut self) {
+ let n = filter_c(self, &self.f()).count();
+ next::<N>(n, &mut self.selection, &mut self.vo);
+ }
+ pub fn cells(&self, c: usize, ws: &Path) -> Vec<Cell> {
+ let f = self.f();
+ let mut out = vec![];
+ let v = score_c(filter_c(self, &f), &f);
+ let vlen = v.len();
+ let i = v.into_iter().zip(0..vlen).skip(self.vo).take(N).rev();
+
+ // let Some((s, x)) = i.next() else {
+ // return vec![];
+ // };
+
+ // let mut q = Dq::<_, 13>::new((s, x));
+ // for (s, x) in i {
+ // if q.first().0 <= s {
+ // q.push_front((s, x));
+ // }
+ // }
+
+ // fuzzy_aho_corasick::FuzzyAhoCorasickBuilder::new()
+ // .fuzzy(
+ // FuzzyLimits::new()
+ // .insertions(20)
+ // .deletions(2)
+ // .edits(4)
+ // .substitutions(5)
+ // .swaps(3),
+ // .penalties(FuzzyPenalties {
+ // )
+ // insertion: 0.0,
+ // deletion: 1.0,
+ // substitution: 0.5,
+ // swap: 0.5,
+ // })
+ // .build(
+ // y.iter().map(|x| x.filter_text.as_deref().unwrap_or(&x.label)),
+ // )
+ // .search(filter, 0.25)
+ // .into_iter()
+ // .map(|x| &y[x.pattern_index])
+ // // .take(13);
+ // // for x in y
+ // // .iter()
+ // // .filter(|x| {
+ // // x.filter_text
+ // // .as_deref()
+ // // .unwrap_or(&x.label)
+ // // .starts_with(filter)
+ // // })
+ // .take(13)
+ i.for_each(|((_, x, indices), i)| {
+ r(x, ws, c, i == self.selection, &indices, &mut out, self.ty)
+ });
+
+ out
}
}
@@ -154,6 +195,41 @@ impl<'a> Key<'a> for UsedSI<'a> {
self.name
}
}
+fn score_c<'a>(
+ x: impl Iterator<Item = UsedSI<'a>>,
+ filter: &'_ str,
+) -> Vec<(u32, UsedSI<'a>, Vec<u32>)> {
+ score(x, filter)
+}
+
+fn filter_c<'a>(
+ syms: &'a Symbols,
+ f: &'_ str,
+) -> impl Iterator<Item = UsedSI<'a>> {
+ let x = &syms.r;
+ filter(
+ match x {
+ SymbolsList::Document(DocumentSymbolResponse::Flat(x)) =>
+ Iter3::A(x.iter().map(UsedSI::from)),
+ SymbolsList::Document(DocumentSymbolResponse::Nested(x)) =>
+ Iter3::B(x.iter().flat_map(|x| gen move {
+ let mut q = VecDeque::with_capacity(12);
+ q.push_back(x);
+ while let Some(x) = q.pop_front() {
+ q.extend(x.children.iter().flatten());
+ yield x.into();
+ }
+ })),
+ SymbolsList::Workspace(WorkspaceSymbolResponse::Flat(x)) =>
+ Iter3::C(chain(&syms.tree, x.iter()).map(UsedSI::from)),
+ _ => unreachable!("please no"),
+ },
+ f,
+ )
+}
+fn charc(c: &str) -> usize {
+ c.chars().count()
+}
#[implicit_fn::implicit_fn]
fn r<'a>(
x: UsedSI<'a>,