A simple CPU rendered GUI IDE experience.
check the caps before
bendn 13 days ago
parent c007094 · commit acce87a
-rw-r--r--src/complete.rs13
-rw-r--r--src/edi.rs42
-rw-r--r--src/edi/input_handlers/click.rs16
-rw-r--r--src/edi/input_handlers/keyboard.rs156
-rw-r--r--src/lsp/client.rs264
-rw-r--r--src/lsp/rq.rs48
-rw-r--r--src/main.rs11
-rw-r--r--src/menu.rs2
8 files changed, 313 insertions, 239 deletions
diff --git a/src/complete.rs b/src/complete.rs
index 8959bba..81c9c2f 100644
--- a/src/complete.rs
+++ b/src/complete.rs
@@ -118,7 +118,7 @@ fn r(
const { CompletionItemKind::TYPE_PARAMETER.0 as usize } => ("#9a9b9a", "T "),
const { CompletionItemKind::KEYWORD.0 as usize } => ("#FFAD66", "as"),
_ => ("#9a9b9a", " ")
- }).map(const
+ }).map(const
|(x, y)| (set_a(color_(x), 0.5), color_(x), y),
)
};
@@ -254,10 +254,11 @@ impl Editor {
if self.hist.record(&self.text) {
change!(self, window.clone());
}
- self.requests.sig_help =
- Rq::new(lsp.runtime.spawn(lsp.request_sig_help(
- o,
- self.text.cursor.first().cursor(&self.text.rope),
- )));
+ if let Ok(fut) = lsp.request_sig_help(
+ o,
+ self.text.cursor.first().cursor(&self.text.rope),
+ ) {
+ self.requests.sig_help = Rq::new(lsp.runtime.spawn(fut));
+ }
}
}
diff --git a/src/edi.rs b/src/edi.rs
index 3e751a7..8d22557 100644
--- a/src/edi.rs
+++ b/src/edi.rs
@@ -38,7 +38,8 @@ use crate::error::WDebug;
use crate::gotolist::{At, GoTo};
use crate::hov::{self, HOV_HEIGHT, Hovr, Hovring, Rendered};
use crate::lsp::{
- Anonymize, Client, Map_, PathURI, RequestError, Rq, tdpp, vsc_settings,
+ Anonymize, Client, Map_, PathURI, Peel, RequestError, Rq, tdpp,
+ vsc_settings,
};
use crate::menu::generic::MenuData;
use crate::meta::META;
@@ -115,11 +116,10 @@ pub(crate) use lsp;
macro_rules! inlay {
($self:ident) => {
$crate::edi::lsp!($self + p).map(|(lsp, path)| {
- $self
- .requests
- .inlay
- .request(lsp.runtime.spawn(lsp.inlay(path, &$self.text)))
- })
+ if let Ok(fut) = lsp.inlay(path, &$self.text) {
+ $self.requests.inlay.request(lsp.runtime.spawn(fut))
+ }
+ });
};
}
pub(crate) use inlay;
@@ -138,11 +138,11 @@ macro_rules! change {
(@$self:ident, $w:expr) => {
lsp!($self + p).map(|(x, origin)| {
x.edit(&origin, $self.text.rope.to_string()).unwrap();
+ use crate::lsp::Peel;
x.rq_semantic_tokens(
&mut $self.requests.semantic_tokens,
origin,
- )
- .unwrap();
+ ).peel().unwrap();
$crate::edi::inlay!($self);
let o_ = $self.origin.clone();
let w = $self.git_dir.clone();
@@ -161,8 +161,8 @@ macro_rules! change {
});
let origin = origin.to_owned();
$self.requests.git_diff.request(t);
- if $self.requests.document_symbols.result != Some(None) {
- let h = x.runtime.spawn(async move { x.document_symbols(&origin).await });
+ if $self.requests.document_symbols.result != Some(None) && let Ok(fut) = x.document_symbols(&origin) {
+ let h = x.runtime.spawn(fut);
$self.requests.document_symbols.request(h);
}
});
@@ -339,7 +339,8 @@ impl Editor {
c.rq_semantic_tokens(
&mut me.requests.semantic_tokens,
origin,
- )?;
+ )
+ .peel()?;
}
me.git_dir = g;
me.mtime = Self::modify(me.origin.as_deref());
@@ -382,16 +383,16 @@ impl Editor {
// );
self.bar.last_action = "saved".into();
lsp!(self + p).map(|(l, o)| {
- let v = l.runtime.block_on(l.format(o));
- if let Ok(Some(v)) = v {
- if let Err(x) =
+ if let Ok(fut) = l.format(o)
+ && let Ok(Some(v)) = l.runtime.block_on(fut)
+ && let Err(x) =
self.text.apply_tedits_adjusting(&mut { v })
- {
- eprintln!("unhappy fmt {x}")
- }
+ {
+ eprintln!("unhappy fmt {x}")
}
- // self.text.cursor =
- // self.text.cursor.min(self.text.rope.len_chars());
+ self.text.cursor.each(|c| {
+ c.position = c.position.min(self.text.rope.len_chars())
+ });
change!(self);
self.hist.push_if_changed(&mut self.text);
l.notify::<lsp_notification!("textDocument/didSave")>(
@@ -600,7 +601,8 @@ impl Editor {
ls.rq_semantic_tokens(
&mut self.requests.semantic_tokens,
origin,
- )?;
+ )
+ .peel()?;
}
}
self.set_title(w);
diff --git a/src/edi/input_handlers/click.rs b/src/edi/input_handlers/click.rs
index 93245c6..d687c60 100644
--- a/src/edi/input_handlers/click.rs
+++ b/src/edi/input_handlers/click.rs
@@ -24,15 +24,12 @@ impl Editor {
text.mapped_index_at(cursor_position),
&text.rope,
);
- if let Some((lsp, path)) = lsp!(self + p) {
- if self.requests.sig_help.result.is_some() {
- self.requests.sig_help.request(lsp.runtime.spawn(
- lsp.request_sig_help(
- path,
- text.primary_cursor(),
- ),
- ));
- }
+ if let Some((lsp, path)) = lsp!(self + p)
+ && self.requests.sig_help.result.is_some()
+ && let Ok(fut) =
+ lsp.request_sig_help(path, text.primary_cursor())
+ {
+ self.requests.sig_help.request(lsp.runtime.spawn(fut));
}
self.hist.lc = text.cursor.clone();
self.chist.push(text.primary_cursor());
@@ -68,7 +65,6 @@ impl Editor {
GotoDefinitionResponse::Link([x, ..]) => Some(x.clone()),
_ => None,
})
-
})
&& let Err(e) = self.go(&x, w.clone())
{
diff --git a/src/edi/input_handlers/keyboard.rs b/src/edi/input_handlers/keyboard.rs
index aaf3fa3..f61a338 100644
--- a/src/edi/input_handlers/keyboard.rs
+++ b/src/edi/input_handlers/keyboard.rs
@@ -77,18 +77,14 @@ impl Editor {
},
Some(Do::DeleteBracketPair) => self.delete_bracket_pair(),
Some(Do::Symbols) =>
- if let Some((lsp, o)) = lsp!(self + p) {
- let mut q = Rq::new(
- lsp.runtime.spawn(
- lsp.workspace_symbols("".into())
- .map(|x| x.anonymize())
- .map(|x| {
- x.map(|x| {
- x.map(SymbolsList::Workspace)
- })
- }),
- ),
- );
+ if let Some((lsp, o)) = lsp!(self + p)
+ && let Ok(syms) = lsp.workspace_symbols("".into())
+ {
+ let mut q = Rq::new(lsp.runtime.spawn(
+ syms.map(Anonymize::anonymize).map(|x| {
+ x.map(|x| x.map(SymbolsList::Workspace))
+ }),
+ ));
q.result = Some(Symbols::new(
self.tree.as_deref().unwrap(),
self.text.bookmarks.clone(),
@@ -106,15 +102,16 @@ impl Editor {
x.data.3 = sym::SymbolsType::Document;
let p = p.to_owned();
take(&mut x.data.0);
- *request = Some((
- DropH::new(lsp.runtime.spawn(async move {
- lsp.document_symbols(&p)
- .await
- .anonymize()
- .map(|x| x.map(SymbolsList::Document))
- })),
- (),
- ));
+ if let Ok(fut) = lsp.document_symbols(&p) {
+ *request = Some((
+ DropH::new(lsp.runtime.spawn(async move {
+ fut.await
+ .anonymize()
+ .map(|x| x.map(SymbolsList::Document))
+ })),
+ (),
+ ));
+ }
},
Some(Do::ProcessCommand(mut x, z)) =>
match Cmds::complete_or_accept(&z) {
@@ -159,23 +156,25 @@ impl Editor {
|| ptedit != x.tedit.rope
{
if x.data.3 == SymbolsType::Workspace {
- *request = Some((
- DropH::new(
- lsp.runtime.spawn(
- lsp.workspace_symbols(
- x.tedit.rope.to_string(),
- )
- .map(|x| {
- x.anonymize().map(|x| {
- x.map(
+ *request = lsp
+ .workspace_symbols(
+ x.tedit.rope.to_string(),
+ )
+ .ok()
+ .map(|fut| {
+ (
+ DropH::new(lsp.runtime.spawn(
+ fut.map(|x| {
+ x.anonymize().map(|x| {
+ x.map(
SymbolsList::Workspace,
)
- })
- }),
- ),
- ),
- (),
- ));
+ })
+ }),
+ )),
+ (),
+ )
+ });
} else {
x.selection = 0;
x.vo = 0;
@@ -669,13 +668,12 @@ impl Editor {
if self.requests.sig_help.running()
&& cb4 != self.text.cursor.first()
&& let Some((lsp, path)) = lsp!(self + p)
+ && let Ok(fut) = lsp.request_sig_help(
+ path,
+ self.text.cursor.first().cursor(&self.text.rope),
+ )
{
- self.requests.sig_help.request(lsp.runtime.spawn(
- lsp.request_sig_help(
- path,
- self.text.cursor.first().cursor(&self.text.rope),
- ),
- ));
+ self.requests.sig_help.request(lsp.runtime.spawn(fut));
}
if self.hist.record(&self.text) {
change!(self, window.clone());
@@ -687,14 +685,13 @@ impl Editor {
&& let Some(x) =
&x.capabilities.signature_help_provider
&& let Some(x) = &x.trigger_characters
- && x.contains(&y.to_string()) =>
- {
- self.requests.sig_help.request(lsp.runtime.spawn(
- lsp.request_sig_help(
+ && x.contains(&y.to_string())
+ && let Ok(fut) = lsp.request_sig_help(
o,
self.text.cursor.first().cursor(&self.text.rope),
- ),
- ));
+ ) =>
+ {
+ self.requests.sig_help.request(lsp.runtime.spawn(fut));
}
_ => {}
}
@@ -705,27 +702,28 @@ impl Editor {
.unwrap()
{
Some(CDo::Request(ctx)) => {
- let h =
- DropH::new(lsp.runtime.spawn(lsp.request_complete(
- o,
- self.text.cursor.first().cursor(&self.text.rope),
- ctx,
- )));
- let CompletionState::Complete(Rq {
- request: x,
- result: c,
- }) = &mut self.requests.complete
- else {
- panic!()
- };
- use ttools::TryRefTuple;
- *x = Some((
- h,
- c.as_ref()
- .map(|x| x.start)
- .or(x.as_ref().on::<1>().copied())
- .unwrap_or(*self.text.cursor.first()),
- ));
+ if let Ok(fut) = lsp.request_complete(
+ o,
+ self.text.cursor.first().cursor(&self.text.rope),
+ ctx,
+ ) {
+ let h = DropH::new(lsp.runtime.spawn(fut));
+ let CompletionState::Complete(Rq {
+ request: x,
+ result: c,
+ }) = &mut self.requests.complete
+ else {
+ panic!()
+ };
+ use ttools::TryRefTuple;
+ *x = Some((
+ h,
+ c.as_ref()
+ .map(|x| x.start)
+ .or(x.as_ref().on::<1>().copied())
+ .unwrap_or(*self.text.cursor.first()),
+ ));
+ }
}
Some(CDo::SelectNext) => {
let CompletionState::Complete(Rq {
@@ -845,15 +843,15 @@ impl Editor {
}
pub fn refresh_document_highlights(&mut self) {
lsp!(let lsp, path = self);
- self.requests.document_highlights.request(
- lsp.runtime.spawn(
- lsp.document_highlights(
- path,
- self.text
- .to_l_position(self.text.cursor.first().position)
- .unwrap(),
- ),
- ),
- );
+ if let Ok(fut) = lsp.document_highlights(
+ path,
+ self.text
+ .to_l_position(self.text.cursor.first().position)
+ .unwrap(),
+ ) {
+ self.requests
+ .document_highlights
+ .request(lsp.runtime.spawn(fut));
+ }
}
}
diff --git a/src/lsp/client.rs b/src/lsp/client.rs
index 8d9b0d8..9bc85b5 100644
--- a/src/lsp/client.rs
+++ b/src/lsp/client.rs
@@ -22,7 +22,7 @@ use tokio::sync::oneshot;
use ttools::*;
use crate::lsp::BehaviourAfter::{self, *};
-use crate::lsp::{RequestError, Rq, Void};
+use crate::lsp::{RequestError, Require, Requiring, Rq};
use crate::text::cursor::ceach;
use crate::text::{LOADER, RopeExt, SortTedits, TextArea};
@@ -118,12 +118,17 @@ impl Client {
f: &Path,
(x, y): (usize, usize),
c: CompletionContext,
- ) -> impl Future<
- Output = Result<
- Option<CompletionResponse>,
- RequestError<Completion>,
- >,
- > + use<'me> {
+ ) -> Requiring<
+ "completion",
+ impl Future<
+ Output = Result<
+ Option<CompletionResponse>,
+ RequestError<Completion>,
+ >,
+ > + use<'me>,
+ > {
+ self.caps().completion_provider.require()?;
+
let (rx, _) = self
.request_::<Completion, { Redraw }>(&CompletionParams {
text_document_position: TextDocumentPositionParams {
@@ -135,35 +140,40 @@ impl Client {
context: Some(c),
})
.unwrap();
- rx
+ Ok(rx)
}
pub fn request_sig_help<'me>(
&'me self,
f: &Path,
(x, y): (usize, usize),
- ) -> impl Future<
- Output = Result<
- Option<SignatureHelp>,
- RequestError<SignatureHelpRequest>,
- >,
- > + use<'me> {
- self.request_::<SignatureHelpRequest, { Redraw }>(
- &SignatureHelpParams {
- context: None,
- text_document_position_params:
- TextDocumentPositionParams {
- text_document: f.tid(),
- position: Position {
- line: y as _,
- character: x as _,
+ ) -> Requiring<
+ "signature_help",
+ impl Future<
+ Output = Result<
+ Option<SignatureHelp>,
+ RequestError<SignatureHelpRequest>,
+ >,
+ > + use<'me>,
+ > {
+ self.caps().signature_help_provider.require()?;
+ Ok(self
+ .request_::<SignatureHelpRequest, { Redraw }>(
+ &SignatureHelpParams {
+ context: None,
+ text_document_position_params:
+ TextDocumentPositionParams {
+ text_document: f.tid(),
+ position: Position {
+ line: y as _,
+ character: x as _,
+ },
},
- },
- work_done_progress_params: default(),
- },
- )
- .unwrap()
- .0
+ work_done_progress_params: default(),
+ },
+ )
+ .unwrap()
+ .0)
}
pub fn _pull_all_diag(
@@ -301,12 +311,16 @@ impl Client {
&'me self,
f: &Path,
cursor: Position,
- ) -> impl Future<
- Output = Result<
- Vec<DocumentHighlight>,
- RequestError<DocumentHighlightRequest>,
- >,
- > + use<'me> {
+ ) -> Requiring<
+ "document_highlights",
+ impl Future<
+ Output = Result<
+ Vec<DocumentHighlight>,
+ RequestError<DocumentHighlightRequest>,
+ >,
+ > + use<'me>,
+ > {
+ self.caps().document_highlight_provider.require()?;
let p = DocumentHighlightParams {
text_document_position_params: TextDocumentPositionParams {
text_document: f.tid(),
@@ -315,21 +329,25 @@ impl Client {
work_done_progress_params: default(),
partial_result_params: default(),
};
- self.request_::<lsp_request!("textDocument/documentHighlight"), {Redraw}>(&p)
+ Ok(self.request_::<lsp_request!("textDocument/documentHighlight"), {Redraw}>(&p)
.unwrap()
.0
- .map(|x| x.map(|x| x.unwrap_or_default()))
+ .map(|x| x.map(|x| x.unwrap_or_default())))
}
pub fn document_symbols(
&'static self,
p: &Path,
- ) -> impl Future<
- Output = Result<
- Option<DocumentSymbolResponse>,
- RequestError<lsp_request!("textDocument/documentSymbol")>,
- >,
+ ) -> Requiring<
+ "document_symbol",
+ impl Future<
+ Output = Result<
+ Option<DocumentSymbolResponse>,
+ RequestError<lsp_request!("textDocument/documentSymbol")>,
+ >,
+ > + use<>,
> {
- self.request_::<lsp_request!("textDocument/documentSymbol"), { Redraw }>(
+ self.caps().document_symbol_provider.require()?;
+ Ok(self.request_::<lsp_request!("textDocument/documentSymbol"), { Redraw }>(
&DocumentSymbolParams {
text_document: p.tid(),
work_done_progress_params: default(),
@@ -337,31 +355,36 @@ impl Client {
},
)
.unwrap()
- .0
+ .0)
}
pub fn workspace_symbols(
&'static self,
f: String,
- ) -> impl Future<
- Output = Result<
- Option<WorkspaceSymbolResponse>,
- RequestError<lsp_request!("workspace/symbol")>,
+ ) -> Requiring<
+ "workspace_symbol",
+ impl Future<
+ Output = Result<
+ Option<WorkspaceSymbolResponse>,
+ RequestError<lsp_request!("workspace/symbol")>,
+ >,
>,
> {
- self.request_::<lsp_request!("workspace/symbol"), { Redraw }>(
- &lsp_types::WorkspaceSymbolParams {
- query: f,
- search_scope: Some(
- lsp_types::WorkspaceSymbolSearchScope::Workspace,
- ),
- search_kind: Some(
- lsp_types::WorkspaceSymbolSearchKind::AllSymbols,
- ),
- ..Default::default()
- },
- )
- .unwrap()
- .0
+ self.caps().workspace_symbol_provider.require()?;
+ Ok(self
+ .request_::<lsp_request!("workspace/symbol"), { Redraw }>(
+ &lsp_types::WorkspaceSymbolParams {
+ query: f,
+ search_scope: Some(
+ lsp_types::WorkspaceSymbolSearchScope::Workspace,
+ ),
+ search_kind: Some(
+ lsp_types::WorkspaceSymbolSearchKind::AllSymbols,
+ ),
+ ..Default::default()
+ },
+ )
+ .unwrap()
+ .0)
}
pub fn matching_brace_at(
@@ -400,19 +423,23 @@ impl Client {
&'static self,
f: &Path,
t: &TextArea,
- ) -> impl Future<
- Output = Result<
- Vec<InlayHint>,
- RequestError<lsp_request!("textDocument/inlayHint")>,
- >,
- > + use<> {
- self.request_::<lsp_request!("textDocument/inlayHint"), { Redraw }>(&InlayHintParams {
+ ) -> Requiring<
+ "inlay_hint",
+ impl Future<
+ Output = Result<
+ Vec<InlayHint>,
+ RequestError<lsp_request!("textDocument/inlayHint")>,
+ >,
+ > + use<>,
+ > {
+ self.caps().inlay_hint_provider.require()?;
+ Ok(self.request_::<lsp_request!("textDocument/inlayHint"), { Redraw }>(&InlayHintParams {
work_done_progress_params: default(),
text_document: f.tid(),
range: t.to_l_range(lower::saturating::math!{
t.rope.try_line_to_char(t.vo-t.r).unwrap_or(0)..t.rope.try_line_to_char(t.vo + t.r + t.r).unwrap_or(t.rope.len_chars())
}).unwrap()
- }).unwrap().0.map(|x| x.map(Option::unwrap_or_default))
+ }).unwrap().0.map(|x| x.map(Option::unwrap_or_default)))
// async {
// if let Ok(z) = z.await {
// let mut into = vec![];
@@ -431,25 +458,33 @@ impl Client {
pub fn format(
&'static self,
f: &Path,
- ) -> impl Future<
- Output = Result<Option<Vec<TextEdit>>, RequestError<Formatting>>,
+ ) -> Requiring<
+ "document_formatting",
+ impl Future<
+ Output = Result<
+ Option<Vec<TextEdit>>,
+ RequestError<Formatting>,
+ >,
+ >,
> {
- self.request::<lsp_request!("textDocument/formatting")>(
- &DocumentFormattingParams {
- text_document: f.tid(),
- options: FormattingOptions {
- tab_size: 4,
- insert_spaces: false,
- properties: default(),
- trim_trailing_whitespace: Some(true),
- insert_final_newline: Some(true),
- trim_final_newlines: Some(false),
+ self.caps().document_formatting_provider.require()?;
+ Ok(self
+ .request::<lsp_request!("textDocument/formatting")>(
+ &DocumentFormattingParams {
+ text_document: f.tid(),
+ options: FormattingOptions {
+ tab_size: 4,
+ insert_spaces: false,
+ properties: default(),
+ trim_trailing_whitespace: Some(true),
+ insert_final_newline: Some(true),
+ trim_final_newlines: Some(false),
+ },
+ work_done_progress_params: default(),
},
- work_done_progress_params: default(),
- },
- )
- .unwrap()
- .0
+ )
+ .unwrap()
+ .0)
}
pub fn rq_semantic_tokens(
&'static self,
@@ -460,38 +495,39 @@ impl Client {
RequestError<SemanticTokensFullRequest>,
>,
f: &Path,
- ) -> Result<(), RequestError<SemanticTokensFullRequest>> {
- self.caps().semantic_tokens_provider.void().ok_or(
- RequestError::<SemanticTokensFullRequest>::Unsupported,
- )?;
+ ) -> Requiring<
+ "semantic_tokens",
+ Result<(), RequestError<SemanticTokensFullRequest>>,
+ > {
+ self.caps().semantic_tokens_provider.require()?;
debug!("requested semantic tokens");
// let Some(b"rs") = f.extension().map(|x| x.as_encoded_bytes())
// else {
// return Ok(());
// };
- let (rx, _) = self.request::<SemanticTokensFullRequest>(
- &SemanticTokensParams {
- work_done_progress_params: default(),
- partial_result_params: default(),
- text_document: f.tid(),
- },
- )?;
- let x = self.runtime.spawn(async move {
- let t = rx.await;
- let y =
- t?.ok_or(RequestError::Rx(std::marker::PhantomData))?;
- debug!("received semantic tokens");
- let r = match y {
- SemanticTokensResult::Partial(_) =>
- panic!("i told the lsp i dont support this"),
- SemanticTokensResult::Tokens(x) =>
- x.data.into_boxed_slice(),
- };
- Ok(r)
- });
- to.request(x);
-
- Ok(())
+ Ok(try bikeshed Result<(), RequestError<_>> {
+ let (rx, _) = self.request::<SemanticTokensFullRequest>(
+ &SemanticTokensParams {
+ work_done_progress_params: default(),
+ partial_result_params: default(),
+ text_document: f.tid(),
+ },
+ )?;
+ let x = self.runtime.spawn(async move {
+ let t = rx.await;
+ let y =
+ t?.ok_or(RequestError::Rx(std::marker::PhantomData))?;
+ debug!("received semantic tokens");
+ let r = match y {
+ SemanticTokensResult::Partial(_) =>
+ panic!("i told the lsp i dont support this"),
+ SemanticTokensResult::Tokens(x) =>
+ x.data.into_boxed_slice(),
+ };
+ Ok(r)
+ });
+ to.request(x);
+ })
}
pub fn enter<'a>(
diff --git a/src/lsp/rq.rs b/src/lsp/rq.rs
index f2cf34d..1d7ef09 100644
--- a/src/lsp/rq.rs
+++ b/src/lsp/rq.rs
@@ -1,5 +1,5 @@
use std::backtrace::Backtrace;
-use std::fmt::Debug;
+use std::fmt::{Debug, Display};
use std::marker::PhantomData;
use crossbeam::channel::SendError;
@@ -11,13 +11,15 @@ use tokio::sync::oneshot;
use tokio::task;
use tokio_util::task::AbortOnDropHandle;
+use crate::lsp::Void;
+
#[derive(Serialize, Deserialize)]
pub enum RequestError<X> {
Rx(PhantomData<X>),
Failure(Re, #[serde(skip)] Option<Backtrace>),
Cancelled(Re, DiagnosticServerCancellationData),
Send(Message),
- Unsupported,
+ // Unsupported,
}
pub type AQErr = RequestError<LSPError>;
impl Request for LSPError {
@@ -37,7 +39,7 @@ impl<T, E> Anonymize<T> for Result<T, RequestError<E>> {
RequestError::Rx(_) => RequestError::Rx(PhantomData),
RequestError::Failure(r, b) => RequestError::Failure(r, b),
RequestError::Cancelled(r, d) => RequestError::Cancelled(r, d),
- RequestError::Unsupported => RequestError::Unsupported,
+ // RequestError::Unsupported => RequestError::Unsupported,
})
}
}
@@ -65,8 +67,8 @@ impl<X: Request> std::fmt::Display for RequestError<X> {
write!(f, "{} failed; couldnt send {x:?}", X::METHOD),
Self::Rx(_) =>
write!(f, "{} failed; couldnt get from thingy", X::METHOD),
- RequestError::Unsupported =>
- write!(f, "{} failed; detected as unsupported", X::METHOD),
+ // RequestError::Unsupported =>
+ // write!(f, "{} failed; detected as unsupported", X::METHOD),
Self::Failure(x, bt) => write!(
f,
"{} failed; returned badge :( {x:?} ({bt:?})",
@@ -82,6 +84,42 @@ impl<R: Request> Debug for RequestError<R> {
std::fmt::Display::fmt(&self, f)
}
}
+pub trait Require<const R: &'static str> {
+ fn require(&self) -> Requiring<R, ()>;
+}
+impl<T, const R: &'static str> Require<R> for Option<T> {
+ fn require(&self) -> Requiring<R, ()> {
+ self.void().ok_or(Unsupported)
+ }
+}
+pub struct Unsupported<const R: &'static str>;
+pub type Requiring<const R: &'static str, T> = Result<T, Unsupported<R>>;
+impl<const R: &'static str> Display for Unsupported<R> {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "request {} isnt supported by this LSP", R)
+ }
+}
+pub trait Peel<E> {
+ fn peel(self) -> Result<(), E>;
+}
+impl<E, N> Peel<E> for Result<Result<(), E>, N> {
+ fn peel(self) -> Result<(), E> {
+ match self {
+ Ok(Err(e)) => Err(e),
+ Ok(Ok(_)) | Err(_) => Ok(()),
+ }
+ }
+}
+// impl<const R: &'static str> Debug for Unsupported<R> {
+// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+// std::fmt::Display::fmt(&self, f)
+// }
+// }
+// impl<const X: &'static str> std::error::Error for Unsupported<X> {
+// fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
+// None
+// }
+// }
fn none<T>() -> Option<T> {
None
diff --git a/src/main.rs b/src/main.rs
index 6c58cc6..95d2c5e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,4 +1,5 @@
#![feature(
+unsized_const_params,
exact_div,
yeet_expr,
const_array,
@@ -65,7 +66,6 @@ use fimg::Image;
use libc::{atexit, signal};
use lsp::Rq;
use lsp_types::*;
-
use rust_fsm::StateMachine;
use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize};
@@ -100,7 +100,10 @@ fn main() {
let _x = 4;
// let x = HashMap::new();
unsafe { std::env::set_var("CARGO_UNSTABLE_RUSTC_UNICODE", "true") };
- env_logger::builder().filter_level(log::LevelFilter::Info).parse_env("GRA_LOG").init();
+ env_logger::builder()
+ .filter_level(log::LevelFilter::Info)
+ .parse_env("GRA_LOG")
+ .init();
// lsp::x();
entry(EventLoop::new().unwrap())
}
@@ -119,7 +122,7 @@ extern "C" fn sigint(_: i32) {
cleanup();
std::process::exit(12);
}
-type Freq = FxHashMap<TypeId, FxHashMap<u64, u16>>;
+type Freq = FxHashMap<TypeId, FxHashMap<u64, u16>>;
pub(crate) fn entry(event_loop: EventLoop) {
unsafe {
__ED.write(match Editor::new() {
@@ -134,7 +137,7 @@ pub(crate) fn entry(event_loop: EventLoop) {
unsafe { signal(libc::SIGINT, sigint as *const () as usize) };
let ed: &'static mut Editor = unsafe { __ED.assume_init_mut() };
- let mut freq:Freq = default();
+ let mut freq: Freq = default();
let ppem = 18.0;
let ls = 20.0;
// let ed = Box::leak(Box::new(ed));
diff --git a/src/menu.rs b/src/menu.rs
index 06a5d16..7186908 100644
--- a/src/menu.rs
+++ b/src/menu.rs
@@ -6,8 +6,8 @@ use std::sync::LazyLock;
use itertools::Itertools;
-use crate::menu::generic::MenuData;
use crate::Freq;
+use crate::menu::generic::MenuData;
#[lower::apply(saturating)]
pub fn next<const N: usize>(n: usize, sel: &mut usize, vo: &mut usize) {