A simple CPU rendered GUI IDE experience.
-rw-r--r--Cargo.toml2
-rw-r--r--src/lsp.rs32
-rw-r--r--src/main.rs33
-rw-r--r--src/text.rs7
4 files changed, 27 insertions, 47 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 1909cfd..fdedde9 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -24,7 +24,6 @@ rust-fsm = { version = "0.8.0", path = "../rust-fsm/rust-fsm", features = [
"diagram",
] }
clipp = "0.1.0"
-parking_lot = "0.12.4"
diff-match-patch-rs = "0.5.1"
regex = "1.11.3"
tree-house = { version = "0.3.0", features = ["fixtures"] }
@@ -42,7 +41,6 @@ lsp-types = { path = "../helix/helix-lsp-types", package = "helix-lsp-types" }
env_logger = "0.11.8"
url = "2.5.7"
anyhow = "1.0.100"
-arc-swap = "1.7.1"
tokio = { version = "1.47.1", features = ["rt-multi-thread", "sync"] }
regex-cursor = "0.1.5"
papaya = "0.2.3"
diff --git a/src/lsp.rs b/src/lsp.rs
index 2e6511b..912b195 100644
--- a/src/lsp.rs
+++ b/src/lsp.rs
@@ -9,8 +9,6 @@ use std::thread::spawn;
use std::time::Instant;
use Default::default;
-use anyhow::Error;
-use arc_swap::ArcSwap;
use crossbeam::channel::{
Receiver, RecvError, SendError, Sender, unbounded,
};
@@ -21,7 +19,6 @@ use lsp_server::{
use lsp_types::notification::*;
use lsp_types::request::*;
use lsp_types::*;
-use parking_lot::Mutex;
use serde_json::json;
use tokio::sync::oneshot;
use tokio_util::task::AbortOnDropHandle;
@@ -40,10 +37,6 @@ pub struct Client {
>,
pub not_rx: Receiver<N>,
// pub req_rx: Receiver<Rq>,
- pub semantic_tokens: (
- &'static ArcSwap<Box<[SemanticToken]>>,
- Mutex<Option<(tokio::task::JoinHandle<Result<(), Error>>, i32)>>,
- ),
}
impl Drop for Client {
@@ -204,6 +197,7 @@ impl Client {
pub fn rq_semantic_tokens(
&'static self,
+ to: &mut Rq<Box<[SemanticToken]>, Box<[SemanticToken]>>,
f: &Path,
w: Option<Arc<Window>>,
) -> anyhow::Result<()> {
@@ -213,13 +207,7 @@ impl Client {
else {
return Ok(());
};
- let mut p = self.semantic_tokens.1.lock();
- if let Some((h, _task)) = &*p {
- if !h.is_finished() {
- h.abort();
- }
- }
- let (rx, id) = self.request::<SemanticTokensFullRequest>(
+ let (rx, _) = self.request::<SemanticTokensFullRequest>(
&SemanticTokensParams {
work_done_progress_params: default(),
partial_result_params: default(),
@@ -228,21 +216,19 @@ impl Client {
),
},
)?;
- let d = self.semantic_tokens.0;
let x = self.runtime.spawn(async move {
let y = rx.await?.unwrap();
debug!("received semantic tokens");
-
- match y {
+ let r = match y {
SemanticTokensResult::Partial(_) =>
panic!("i told the lsp i dont support this"),
SemanticTokensResult::Tokens(x) =>
- d.store(x.data.into_boxed_slice().into()),
+ x.data.into_boxed_slice(),
};
w.map(|x| x.request_redraw());
- anyhow::Ok(())
+ Ok(r)
});
- *p = Some((x, id));
+ to.request(x);
Ok(())
}
@@ -266,12 +252,6 @@ pub fn run(
.unwrap(),
id: AtomicI32::new(0),
initialized: None,
- semantic_tokens: (
- Box::leak(Box::new(ArcSwap::new(
- vec![].into_boxed_slice().into(),
- ))),
- Mutex::new(None),
- ),
send_to: req_tx,
not_rx,
};
diff --git a/src/main.rs b/src/main.rs
index 330d446..759ebc8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -30,7 +30,7 @@
use std::borrow::Cow;
use std::num::NonZeroU32;
use std::path::{Path, PathBuf};
-use std::sync::{Arc, LazyLock};
+use std::sync::LazyLock;
use std::time::Instant;
use Default::default;
@@ -242,6 +242,7 @@ pub(crate) fn entry(event_loop: EventLoop<()>) {
let mut complete = CompletionState::None;
let mut sig_help = // vo, lines
RqS::<(SignatureHelp, usize, Option<usize>), SignatureHelpRequest, ()>::default();
+ let mut semantic_tokens = default();
// let mut complete = None::<(CompletionResponse, (usize, usize))>;
// let mut complete_ = None::<(
// JoinHandle<
@@ -269,7 +270,7 @@ pub(crate) fn entry(event_loop: EventLoop<()>) {
};
}
- lsp!().map(|(x, origin)| x.rq_semantic_tokens(origin, None).unwrap());
+ lsp!().map(|(x, origin)| x.rq_semantic_tokens(&mut semantic_tokens, origin, None).unwrap());
let mut mtime: Option<std::time::SystemTime> = modify!();
macro_rules! save {
() => {{
@@ -310,7 +311,7 @@ pub(crate) fn entry(event_loop: EventLoop<()>) {
() => {
lsp!().map(|(x, origin)| {
x.edit(&origin, text.rope.to_string()).unwrap();
- x.rq_semantic_tokens(origin, Some(window.clone())).unwrap();
+ x.rq_semantic_tokens(&mut semantic_tokens, origin, Some(window.clone())).unwrap();
});
};
}
@@ -336,6 +337,7 @@ pub(crate) fn entry(event_loop: EventLoop<()>) {
f.ok().flatten().map(|x| {Complete {r:x,start:c,selection:0,vo:0,}})
}, &l.runtime);
};
+ semantic_tokens.poll(|x, _| x.ok(), &l.runtime);
sig_help.poll(|x, ((), y)| x.ok().flatten().map(|x| {
if let Some((old_sig, vo, max)) = y && &sig::active(&old_sig) == &sig::active(&x){
(x, vo, max)
@@ -440,16 +442,19 @@ pub(crate) fn entry(event_loop: EventLoop<()>) {
}
},
origin.as_deref(),
- lsp!().and_then(|(x, _)| { match &x.initialized {
- Some(lsp_types::InitializeResult {
+ semantic_tokens.result.as_deref().zip(
+ match lsp {
+ Some(lsp::Client { initialized: Some(lsp_types::InitializeResult {
capabilities: ServerCapabilities {
- semantic_tokens_provider:
- Some(SemanticTokensServerCapabilities::SemanticTokensOptions(SemanticTokensOptions{
- legend,..
- })),..
- },..
- }) => Some(legend), _ => None, }}.map(|leg|(x.semantic_tokens.0.load(), leg))
- ),
+ semantic_tokens_provider:
+ Some(SemanticTokensServerCapabilities::SemanticTokensOptions(SemanticTokensOptions{
+ legend,..
+ })),..
+ }, ..
+ }), ..
+ }) => Some(legend),
+ _ => None,
+ }),
);
bar.write_to(
@@ -1028,9 +1033,9 @@ hovering.request = (DropH::new(handle), hover).into();
mtime = modify!();
lsp!().map(|(x, origin)| {
- x.semantic_tokens.0.store(Arc::new(vec![].into()));
+ semantic_tokens = default();
x.open(&origin,new).unwrap();
- x.rq_semantic_tokens(origin, Some(window.clone())).unwrap();
+ x.rq_semantic_tokens(&mut semantic_tokens, origin, Some(window.clone())).unwrap();
});
bar.last_action = "open".to_string();
};
diff --git a/src/text.rs b/src/text.rs
index e67a0c8..c57e824 100644
--- a/src/text.rs
+++ b/src/text.rs
@@ -739,10 +739,7 @@ impl TextArea {
selection: Option<Range<usize>>,
apply: impl FnOnce((usize, usize), &mut Self, Output),
path: Option<&Path>,
- tokens: Option<(
- arc_swap::Guard<Arc<Box<[SemanticToken]>>>,
- &SemanticTokensLegend,
- )>,
+ tokens: Option<(&[SemanticToken], &SemanticTokensLegend)>,
) {
let (c, r) = (self.c, self.r);
let mut cells = Output {
@@ -789,7 +786,7 @@ impl TextArea {
{
let mut ln = 0;
let mut ch = 0;
- for t in &**t {
+ for t in t {
ln += t.delta_line;
ch = match t.delta_line {
1.. => t.delta_start,