A simple CPU rendered GUI IDE experience.
fix warnings
| -rw-r--r-- | src/act.rs | 8 | ||||
| -rw-r--r-- | src/bar.rs | 4 | ||||
| -rw-r--r-- | src/edi.rs | 37 | ||||
| -rw-r--r-- | src/edi/st.rs | 6 | ||||
| -rw-r--r-- | src/hov.rs | 3 | ||||
| -rw-r--r-- | src/lsp.rs | 34 | ||||
| -rw-r--r-- | src/rnd.rs | 11 | ||||
| -rw-r--r-- | src/sni.rs | 2 | ||||
| -rw-r--r-- | src/sym.rs | 1 | ||||
| -rw-r--r-- | src/text.rs | 29 | ||||
| -rw-r--r-- | src/text/cursor.rs | 3 | ||||
| -rw-r--r-- | src/text/semantic_tokens.rs | 14 | ||||
| -rw-r--r-- | src/trm.rs | 10 |
13 files changed, 65 insertions, 97 deletions
@@ -4,12 +4,12 @@ use itertools::Itertools; use lsp_types::{CodeAction, CodeActionKind}; #[derive(Debug, Clone)] -enum N<T> { +pub enum N<T> { One(T), Many(Vec<T>, Entry, Vec<String>), } #[derive(Debug, Clone, Copy)] -enum Entry { +pub enum Entry { Inside(usize), Outside(usize), } @@ -59,7 +59,7 @@ impl CodeActions { // } // }; match &mut self.inner { - N::Many(x, Entry::Outside(y), so) => { + N::Many(x, Entry::Outside(y), _) => { let n = x.len(); next::<{ N }>(n, y, &mut self.vo); } @@ -85,7 +85,7 @@ impl CodeActions { } pub fn left(&mut self) { match &mut self.inner { - N::Many(items, x @ Entry::Inside(_), items1) => { + N::Many(_, x @ Entry::Inside(_), _) => { let Entry::Inside(y) = x else { unreachable!() }; *x = Entry::Outside(*y); } @@ -7,7 +7,7 @@ use lsp_types::WorkDoneProgress; use crate::lsp::{Client, Rq}; use crate::rnd::simplify_path; use crate::sym::Symbols; -use crate::text::{RopeExt, TextArea}; +use crate::text::TextArea; #[derive(Default, Debug)] pub struct Bar { pub last_action: String, @@ -22,7 +22,7 @@ impl Bar { oy: usize, fname: &str, state: &super::State, - t: &TextArea, + _t: &TextArea, lsp: Option<&Client>, ) { let fname = simplify_path(fname); @@ -3,9 +3,8 @@ use std::collections::HashMap; use std::mem::take; use std::ops::ControlFlow; use std::path::{Path, PathBuf}; -use std::pin::pin; use std::sync::Arc; -use std::time::{Instant, SystemTime}; +use std::time::SystemTime; use Default::default; use implicit_fn::implicit_fn; @@ -42,6 +41,7 @@ use crate::{ BoolRequest, CDo, ClickHistory, CompletionAction, CompletionState, Hist, act, alt, ctrl, filter, hash, shift, sig, sym, trm, }; +#[allow(dead_code)] pub fn serialize_tokens<S: serde::Serializer>( s: &Rq< Box<[SemanticToken]>, @@ -56,7 +56,7 @@ pub fn serialize_tokens<S: serde::Serializer>( ser, ) } - +#[allow(dead_code)] pub fn deserialize_tokens<'de, D: serde::Deserializer<'de>>( ser: D, ) -> Result< @@ -217,7 +217,7 @@ impl Editor { .and_then(|x| x.canonicalize().ok()); std::env::args().nth(1).map(|x| { - me.text.insert(&std::fs::read_to_string(x).unwrap()).unwrap(); + me.text.insert(&std::fs::read_to_string(x).unwrap()); me.text.cursor = default(); }); me.workspace = o @@ -247,7 +247,7 @@ impl Editor { .map(|x| x.path().to_owned()) .collect::<Vec<_>>() }); - let l = me.workspace.as_ref().map(|(workspace)| { + let l = me.workspace.as_ref().map(|workspace| { let dh = std::panic::take_hook(); let main = std::thread::current_id(); // let mut c = Command::new("rust-analyzer") @@ -1123,13 +1123,6 @@ impl Editor { .0, ) .unwrap(); - let mut f_ = |edits: &mut [SnippetTextEdit]| { - edits.sort_tedits(); - // let mut first = false; - for edit in edits { - self.text.apply_snippet_tedit(edit).unwrap(); - } - }; let f = f.to_owned(); act.edit.map(|x| self.apply_wsedit(x, &f)); } @@ -1153,6 +1146,8 @@ impl Editor { Do::Reinsert | Do::GoToDefinition | Do::MoveCursor + | Do::ExtendSelectionToMouse + | Do::Hover | Do::NavBack | Do::NavForward | Do::InsertCursorAtMouse, @@ -1431,7 +1426,7 @@ impl Editor { _ = self.text.remove(r.into()); // self.text.cursor.first().setc(&self.text.rope); }); - self.text.insert(&c).unwrap(); + self.text.insert(&c); self.text.cursor.clear_selections(); self.hist.push_if_changed(&self.text); change!(self, window.clone()); @@ -1524,11 +1519,11 @@ impl Editor { let new = pieces.intersperse("\n").collect::<String>(); // vscode behaviour: insane? - self.text.insert(&new).unwrap(); + self.text.insert(&new); eprintln!("hrmst"); } } else { - self.text.insert(&clipp::paste()).unwrap(); + self.text.insert(&clipp::paste()); } self.hist.push_if_changed(&self.text); change!(self, window.clone()); @@ -1536,11 +1531,6 @@ impl Editor { Some(Do::OpenFile(x)) => { _ = self.open(Path::new(&x), window.clone()); } - Some( - Do::MoveCursor | Do::ExtendSelectionToMouse | Do::Hover, - ) => { - unreachable!() - } Some(Do::StartSearch(x)) => { let s = Regex::new(&x).unwrap(); let n = s @@ -1678,7 +1668,7 @@ impl Editor { self.files.extend(f); // assert!(f.len() == 0); } - self.open_or_restore(&x, lsp, Some(w), ws); + self.open_or_restore(&x, lsp, Some(w), ws)?; self.text.r = r; self.tree = tree; @@ -1732,7 +1722,7 @@ impl Editor { let new = std::fs::read_to_string(&x)?; take(&mut self.text); - self.text.insert(&new)?; + self.text.insert(&new); self.text.cursor.just(0, &self.text.rope); self.bar.last_action = "open".into(); self.mtime = Self::modify(self.origin.as_deref()); @@ -1792,7 +1782,7 @@ pub fn handle2<'a>( use Key::*; match key { - Named(Space) => text.insert(" ").unwrap(), + Named(Space) => text.insert(" "), Named(Backspace) if ctrl() => text.backspace_word(), Named(Backspace) => text.backspace(), Named(Home) if ctrl() => { @@ -1848,6 +1838,7 @@ fn cfgdir() -> PathBuf { } const STORE: &str = "state.torrent"; #[track_caller] +#[allow(dead_code)] fn rtt<T: serde::Serialize + serde::Deserialize<'static>>( x: &T, ) -> Result<T, bendy::serde::Error> { diff --git a/src/edi/st.rs b/src/edi/st.rs index 882f2fe..90c16fb 100644 --- a/src/edi/st.rs +++ b/src/edi/st.rs @@ -1,4 +1,4 @@ -use std::ops::Range; +#![allow(unused_parens, unused_variables, dead_code)] use Default::default; use NamedKey::*; @@ -7,8 +7,8 @@ use regex::Regex; use winit::event::MouseButton; use winit::keyboard::{Key, NamedKey, SmolStr}; -use crate::lsp::{AQErr, RequestError, Rq, RqS}; -use crate::sym::{Symbols, SymbolsType}; +use crate::lsp::{AQErr, Rq, RqS}; +use crate::sym::Symbols; use crate::text::TextArea; use crate::{ BoolRequest, CLICKING, InputRequest, act, alt, ctrl, handle, shift, @@ -1,5 +1,4 @@ use std::iter::{empty, once, repeat_n}; -use std::ops::Range; use std::pin::pin; use std::vec::Vec; @@ -309,4 +308,4 @@ pub struct Hovr { pub(crate) item: crate::text::CellBuffer, } -type VisualX = usize; +pub type VisualX = usize; @@ -2,7 +2,7 @@ use std::backtrace::Backtrace; use std::collections::HashMap; use std::fmt::Display; use std::marker::PhantomData; -use std::mem::{MaybeUninit, forget}; +use std::mem::forget; use std::path::{Path, PathBuf}; use std::sync::Arc; use std::sync::atomic::AtomicI32; @@ -47,6 +47,8 @@ pub struct Client { Option<(WorkDoneProgress, WorkDoneProgressBegin)>, >, pub diagnostics: &'static papaya::HashMap<Url, Vec<Diagnostic>>, + #[allow(dead_code)] + // TODO: handle notifications from the server pub not_rx: Receiver<N>, pub req_rx: Receiver<LRq>, } @@ -285,9 +287,9 @@ impl Client { .0 } - pub fn pull_all_diag( + pub fn _pull_all_diag( &self, - f: PathBuf, + _f: PathBuf, ) -> impl Future<Output = anyhow::Result<()>> { let r = self .request::<lsp_request!("workspace/diagnostic")>(&default()) @@ -319,7 +321,7 @@ impl Client { Ok(()) } } - pub fn pull_diag( + pub fn _pull_diag( &self, f: PathBuf, previous: Option<String>, @@ -352,7 +354,7 @@ impl Client { async move { let x = match r.await { Ok(x) => x, - Err(RequestError::Cancelled(x, y)) if y.retrigger_request => { + Err(RequestError::Cancelled(_, y)) if y.retrigger_request => { self.request::<lsp_request!("textDocument/diagnostic")>(&p,).unwrap().0.await? }, Err(e) => return Err(e.into()), @@ -1041,7 +1043,7 @@ pub fn run( // } // } -trait Void<T> { +pub trait Void<T> { fn void(self) -> Result<T, ()>; } impl<T, E> Void<T> for Result<T, E> { @@ -1083,26 +1085,6 @@ impl<T, U, F: FnMut(T) -> U, Fu: Future<Output = T>> Map_<T, U, F> for Fu { } } -#[derive(Debug)] -pub enum OnceOff<T> { - Waiting(task::JoinHandle<Result<T, oneshot::error::RecvError>>), - Waited(T), -} -impl<T> OnceOff<T> { - pub fn poll( - &mut self, - r: &tokio::runtime::Runtime, - ) -> anyhow::Result<()> { - match self { - OnceOff::Waiting(join_handle) if join_handle.is_finished() => { - *self = Self::Waited(r.block_on(join_handle)??); - } - _ => {} - } - Ok(()) - } -} - impl<R: Request> std::fmt::Debug for RequestError<R> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(&self, f) @@ -1,20 +1,17 @@ -use std::borrow::Cow; use std::iter::once; use std::os::fd::AsFd; use std::sync::{Arc, LazyLock}; use std::time::Instant; use atools::prelude::*; -use crossbeam::channel::select_biased; use dsb::cell::Style; -use dsb::{Cell, Fonts}; +use dsb::Cell; use fimg::pixels::Blend; use fimg::{Image, OverlayAt}; use lsp_types::*; use regex::Regex; use rust_fsm::StateMachine; use softbuffer::Surface; -use swash::{FontRef, Instance}; use url::Url; use winit::dpi::{PhysicalPosition, PhysicalSize}; use winit::window::Window; @@ -104,7 +101,7 @@ pub fn render( // v.iter().map(_.value.clone()).collect::<String>() // }, // }; - // text.rope.insert(text.l_position(inlay.position).unwrap() + off, &label); + // text.rope.insert(text.l_position(inlay.position) + off, &label); // off += label.chars().count(); // } // } @@ -557,7 +554,7 @@ pub fn render( println!("rah"); break 'out; }; - let Ok((is_above, left, top, w, mut h)) = place_around( + let Ok((_is_above, left, top, w, h)) = place_around( (_x, _y), i.copy(), &c, @@ -587,7 +584,7 @@ pub fn render( // let (_x, _y) = text.cursor_visual(); let _x = 0; let _y = r - 1; - let Ok((is_above, left, top, w, mut h)) = place_around( + let Ok((_is_above, left, top, w, h)) = place_around( (_x, _y), i.copy(), &c, @@ -106,4 +106,4 @@ impl Snippet { } } } -type Stop = usize; +pub type Stop = usize; @@ -42,6 +42,7 @@ impl Symbols { uri: Url::from_file_path(&x).unwrap(), }, container_name: None, + #[allow(deprecated)] deprecated: None, tags: None, }) diff --git a/src/text.rs b/src/text.rs index df22c64..4ec7630 100644 --- a/src/text.rs +++ b/src/text.rs @@ -30,6 +30,7 @@ use inlay::{Inlay, Marking}; pub mod semantic_tokens; use semantic_tokens::{TokenD, theme}; +use crate::lsp::Void; use crate::sni::{Snippet, StopP}; theme! { @@ -86,7 +87,7 @@ macro_rules! col { #[derive(Debug)] struct E; impl Display for E { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { Ok(()) } } @@ -139,7 +140,7 @@ impl Diff { .unwrap() .0, ); - let (cu, vo) = self.data[redo as usize].clone(); + let (cu, _vo) = self.data[redo as usize].clone(); t.cursor = cu; t.scroll_to_cursor_centering(); // t.vo = vo; @@ -381,6 +382,7 @@ impl TextArea { } #[implicit_fn::implicit_fn] + #[allow(dead_code)] pub fn raw_index_at(&self, (x, y): (usize, usize)) -> Option<usize> { let x = x.checked_sub(self.line_number_offset() + 1)? + self.ho; Some(self.vo + y) @@ -492,25 +494,24 @@ impl TextArea { Ok(()) } - pub fn insert(&mut self, c: &str) -> Result<(), ropey::Error> { + pub fn insert(&mut self, c: &str) { for i in 0..self.cursor.inner.len() { let cursor = *self.cursor.inner.get(i).expect("aw dangit"); - self.insert_at(cursor.position, c)?; + self.insert_at(cursor.position, c).expect(""); } self.set_ho(); - Ok(()) } pub fn apply(&mut self, x: &TextEdit) -> Result<(usize, usize), ()> { let begin = self.l_position(x.range.start).ok_or(())?; let end = self.l_position(x.range.end).ok_or(())?; - self.remove(begin..end).map_err(|_| ())?; - self.insert_at(begin, &x.new_text).map_err(|_| ())?; + self.remove(begin..end).void()?; + self.insert_at(begin, &x.new_text).void()?; Ok((begin, end)) } pub fn apply_adjusting(&mut self, x: &TextEdit) -> Result<(), ()> { - let (b, e) = self.apply(&x)?; + let (_b, e) = self.apply(&x)?; if e < self.cursor.first().position { if !self.visible(e) { @@ -575,6 +576,7 @@ impl TextArea { let mut z = self.reverse_source_map(y).unwrap(); (z.nth(x).unwrap_or(x), y) } + #[allow(dead_code)] pub fn visible_(&self) -> Range<usize> { self.rope.line_to_char(self.vo) ..self.rope.line_to_char(self.vo + self.r) @@ -658,7 +660,7 @@ impl TextArea { } pub fn tab(&mut self) { match &mut self.tabstops { - None => self.insert(" ").unwrap(), + None => self.insert(" "), Some(x) => match x.next() { Some(x) => { self.cursor.one(Cursor::new(x.r().end, &self.rope)); @@ -809,7 +811,7 @@ impl TextArea { // at = end; // } } - + #[allow(dead_code)] pub fn slice<'c>( &self, (c, _r): (usize, usize), @@ -1077,7 +1079,7 @@ pub static LOADER: LazyLock<Loader> = LazyLock::new(|| { // }); x }); -// #[test] +#[test] pub fn man() { let _query_str = r#" (line_comment)+ @quantified_nodes @@ -1188,7 +1190,7 @@ pub fn man() { // panic!() } - panic!(); + // panic!(); // let root = syntax.tree().root_node(); // let test = |capture, range| { @@ -1206,7 +1208,7 @@ pub fn man() { // ) // }; // test("quantified_nodes", 1..37); - panic!() + // panic!() } pub fn hl( @@ -1300,6 +1302,7 @@ pub fn hl( /// │ ╰ horiz scroll /// ╰ horizontal offset /// ``` +#[allow(dead_code)] // ? pub struct Mapper { /// c, r pub into_s: (usize, usize), diff --git a/src/text/cursor.rs b/src/text/cursor.rs index 87722af..b98793b 100644 --- a/src/text/cursor.rs +++ b/src/text/cursor.rs @@ -470,7 +470,8 @@ impl Cursors { self.each(|c| c.word_left(r)); self.coalesce(); } - pub fn set_ho(&mut self) { + // FIXME: implement + pub fn _set_ho(&mut self) { // let x = self.cursor_visual().0; // if x < self.ho + 4 { // self.ho = x.saturating_sub(4); diff --git a/src/text/semantic_tokens.rs b/src/text/semantic_tokens.rs index 196f1ff..ff8f9e5 100644 --- a/src/text/semantic_tokens.rs +++ b/src/text/semantic_tokens.rs @@ -91,16 +91,6 @@ theme! { // "union" b"#cccac2", // "unresolvedReference" b"#cccac2", } -const fn of(x: &'static str) -> usize { - let mut i = 0; - while i < NAMES.len() { - if NAMES[i] == x { - return i; - } - i += 1; - } - panic!() -} modified! { 2 "function" . "unsafe" b"#F28779", @@ -172,6 +162,9 @@ impl TextArea { 1.. => t.delta_start, 0 => ch + t.delta_start, }; + if t.length == 0 { + continue; + } let Ok((x1, x2)): ropey::Result<_> = (try { let p1 = self.rope.try_byte_to_char( self.rope.try_line_to_byte(ln as _)? + ch as usize, @@ -185,6 +178,7 @@ impl TextArea { }) else { continue; }; + self.tokens.insert( x1..x2, TokenD { @@ -11,11 +11,11 @@ pub fn toggle(at: &Path) { _ = try bikeshed anyhow::Result<()> { let l = LAST.load(Relaxed); let mut niri = niri::socket::Socket::connect()?; - let Ok(Ok(Response::FocusedWindow(Some(focused)))) = - niri.send(Request::FocusedWindow) - else { - unreachable!() - }; + // let Ok(Ok(Response::FocusedWindow(Some(focused)))) = + // niri.send(Request::FocusedWindow) + // else { + // unreachable!() + // }; if l != !0 { let Ok(Ok(Response::Windows(x))) = niri.send(Request::Windows) else { |