A simple CPU rendered GUI IDE experience.
adjustments
| -rw-r--r-- | src/edi.rs | 94 | ||||
| -rw-r--r-- | src/edi/st.rs | 3 | ||||
| -rw-r--r-- | src/main.rs | 6 | ||||
| -rw-r--r-- | src/sym.rs | 37 |
4 files changed, 70 insertions, 70 deletions
@@ -33,7 +33,7 @@ use crate::lsp::{ self, Anonymize, Client, Map_, PathURI, RedrawAfter, RequestError, Rq, }; use crate::meta::META; -use crate::sym::SymbolsType; +use crate::sym::{Symbols, SymbolsType}; use crate::text::cursor::{Ronge, ceach}; use crate::text::{ self, CoerceOption, Mapping, RopeExt, SortTedits, TextArea, @@ -401,50 +401,12 @@ impl Editor { if let State::Symbols(x) = &mut self.state { x.poll( |x, (_, p)| { - x.ok().map(|r| { - if p.as_ref() - .is_none_or(|x| x.ty == SymbolsType::Workspace) - { - let tree = - self.tree.as_deref().unwrap().iter().map( - |x| SymbolInformation { - name: x - .file_name() - .unwrap() - .to_str() - .unwrap() - .to_string(), - kind: SymbolKind::FILE, - location: Location { - range: lsp_types::Range { - end: default(), - start: default(), - }, - uri: Url::from_file_path(&x) - .unwrap(), - }, - container_name: None, - deprecated: None, - tags: None, - }, - ); - sym::Symbols { - tedit: p - .map(|x| x.tedit) - .unwrap_or_default(), - r: tree.chain(r).collect(), - ..default() // dont care about previous selection - } - } else { - sym::Symbols { - tedit: p - .map(|x| x.tedit) - .unwrap_or_default(), - r, - ty: SymbolsType::Document, - ..default() - } - } + let Some(p) = p else { unreachable!() }; + x.ok().map(|r| sym::Symbols { + r, + selection: 0, + vo: 0, + ..p }) }, &r, @@ -899,11 +861,13 @@ impl Editor { } Some(Do::Symbols) => if let Some(lsp) = lsp!(self) { - self.state = State::Symbols(Rq::new( - lsp.runtime.spawn(window.redraw_after( + let mut q = + Rq::new(lsp.runtime.spawn(window.redraw_after( lsp.symbols("".into()).map(|x| x.anonymize()), - )), - )); + ))); + q.result = + Some(Symbols::new(self.tree.as_deref().unwrap())); + self.state = State::Symbols(q); }, Some(Do::SwitchType) => if let Some((lsp, p)) = lsp!(self + p) { @@ -932,28 +896,32 @@ impl Editor { unreachable!() }; let ptedit = x.tedit.rope.clone(); - if (handle2( + if handle2( &event.logical_key, &mut x.tedit, lsp!(self + p), ) .is_some() - || ptedit != x.tedit.rope) - && x.ty == SymbolsType::Workspace + || ptedit != x.tedit.rope { - *request = Some(( - DropH::new( - lsp.runtime.spawn( - window.redraw_after( - lsp.symbols( - x.tedit.rope.to_string(), - ) - .map(|x| x.anonymize()), + if x.ty == SymbolsType::Workspace { + *request = Some(( + DropH::new( + lsp.runtime.spawn( + window.redraw_after( + lsp.symbols( + x.tedit.rope.to_string(), + ) + .map(|x| x.anonymize()), + ), ), ), - ), - (), - )); + (), + )); + } else { + x.selection = 0; + x.vo = 0; + } // state = State::Symbols(Rq::new(lsp.runtime.spawn(lsp.symbols("".into())))); } } diff --git a/src/edi/st.rs b/src/edi/st.rs index adf0486..62b57b3 100644 --- a/src/edi/st.rs +++ b/src/edi/st.rs @@ -66,7 +66,7 @@ Default => { K(_) => _ [Edit], M(_) => _, }, -Symbols(Rq { result: Some(_x), request: None }) => { +Symbols(Rq { result: Some(_x), request: _rq }) => { K(Key::Named(Tab) if shift()) => _ [SymbolsSelectNext], K(Key::Named(ArrowDown)) => _ [SymbolsSelectNext], K(Key::Named(ArrowUp | Tab)) => _ [SymbolsSelectPrev], @@ -105,6 +105,7 @@ Selection => { K(Key::Character(y) if y == "x" && ctrl()) => Default [Cut], K(Key::Character(y) if y == "c" && ctrl()) => Default [Copy], K(Key::Character(y) if y == "/" && ctrl()) => Default [Comment], + M(_) => _, K(Key::Character(y) if !ctrl()) => Default [Insert(SmolStr => y)], K(Key::Named(ArrowLeft)) => Default [SetCursor(LR => LR::Left)], diff --git a/src/main.rs b/src/main.rs index e4087ee..5314fcf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,11 +58,11 @@ use dsb::cell::Style; use dsb::{Cell, F}; use fimg::Image; use libc::{atexit, signal}; -use lsp::{PathURI, Rq}; +use lsp::Rq; use lsp_types::*; use rust_fsm::StateMachine; -use serde::{Deserialize, Deserializer, Serialize}; -use swash::{FontRef, Instance}; +use serde::{Deserialize, Serialize}; +use swash::FontRef; use winit::event::{ ElementState, Event, Ime, MouseButton, MouseScrollDelta, WindowEvent, }; @@ -1,5 +1,5 @@ -use std::iter::repeat; -use std::path::Path; +use std::iter::{chain, repeat}; +use std::path::{Path, PathBuf}; use Default::default; use dsb::Cell; @@ -13,6 +13,7 @@ use crate::text::{TextArea, col, color_, set_a}; #[derive(Debug, Default)] pub struct Symbols { pub r: Vec<SymbolInformation>, + pub tree: Vec<SymbolInformation>, pub tedit: TextArea, pub selection: usize, pub vo: usize, @@ -27,6 +28,26 @@ pub enum SymbolsType { } const N: usize = 30; impl Symbols { + pub fn new(tree: &[PathBuf]) -> Self { + let tree = tree + .iter() + .map(|x| SymbolInformation { + name: x.file_name().unwrap().to_str().unwrap().to_string(), + kind: SymbolKind::FILE, + location: Location { + range: lsp_types::Range { + end: default(), + start: default(), + }, + uri: Url::from_file_path(&x).unwrap(), + }, + container_name: None, + deprecated: None, + tags: None, + }) + .collect(); + Self { tree, ..Default::default() } + } fn f(&self) -> String { self.tedit.rope.to_string() } @@ -113,7 +134,17 @@ fn filter_c<'a>( f: &'_ str, ) -> impl Iterator<Item = &'a SymbolInformation> { let x = &completion.r; - filter(x.iter(), sym_as_str, f) + filter( + chain(&completion.tree, x).skip( + if completion.ty == SymbolsType::Document { + completion.tree.len() + } else { + 0 + }, + ), + sym_as_str, + f, + ) } fn sym_as_str(x: &SymbolInformation) -> &str { &x.name |