Unnamed repository; edit this file 'description' to name the repository.
don't kill server on cancellation
bit-aloo 3 months ago
parent a010936 · commit 0f47fea
-rw-r--r--crates/proc-macro-srv-cli/src/main_loop.rs11
-rw-r--r--crates/proc-macro-srv/src/lib.rs13
2 files changed, 18 insertions, 6 deletions
diff --git a/crates/proc-macro-srv-cli/src/main_loop.rs b/crates/proc-macro-srv-cli/src/main_loop.rs
index 869c5f9392..cae6d31f1a 100644
--- a/crates/proc-macro-srv-cli/src/main_loop.rs
+++ b/crates/proc-macro-srv-cli/src/main_loop.rs
@@ -7,10 +7,11 @@ use std::{
io::{self, BufRead, Write},
ops::Range,
};
+use std::panic::panic_any;
use legacy::Message;
-use proc_macro_srv::{EnvSnapshot, ProcMacroClientError, SpanId};
+use proc_macro_srv::{EnvSnapshot, ProcMacroCancelMarker, ProcMacroClientError, SpanId};
struct SpanTrans;
@@ -201,7 +202,7 @@ impl proc_macro_srv::ProcMacroClientInterface for ProcMacroClientHandle<'_> {
match self.roundtrip(bidirectional::SubRequest::FilePath { file_id: file_id.index() }) {
Ok(bidirectional::SubResponse::FilePathResult { name }) => name,
Err(ProcMacroClientError::Cancelled { reason }) => {
- panic!("proc-macro expansion cancelled by client: {reason}");
+ panic_any(ProcMacroCancelMarker { reason });
}
Err(err) => {
panic!("proc-macro IPC failed: {err:?}");
@@ -224,7 +225,7 @@ impl proc_macro_srv::ProcMacroClientInterface for ProcMacroClientHandle<'_> {
}) {
Ok(bidirectional::SubResponse::SourceTextResult { text }) => text,
Err(ProcMacroClientError::Cancelled { reason }) => {
- panic!("proc-macro expansion cancelled by client: {reason}");
+ panic_any(ProcMacroCancelMarker { reason });
}
Err(err) => {
panic!("proc-macro IPC failed: {err:?}");
@@ -240,7 +241,7 @@ impl proc_macro_srv::ProcMacroClientInterface for ProcMacroClientHandle<'_> {
{
Ok(bidirectional::SubResponse::LocalFilePathResult { name }) => name,
Err(ProcMacroClientError::Cancelled { reason }) => {
- panic!("proc-macro expansion cancelled by client: {reason}");
+ panic_any(ProcMacroCancelMarker { reason });
}
Err(err) => {
panic!("proc-macro IPC failed: {err:?}");
@@ -262,7 +263,7 @@ impl proc_macro_srv::ProcMacroClientInterface for ProcMacroClientHandle<'_> {
Some((line, column))
}
Err(ProcMacroClientError::Cancelled { reason }) => {
- panic!("proc-macro expansion cancelled by client: {reason}");
+ panic_any(ProcMacroCancelMarker { reason });
}
Err(err) => {
panic!("proc-macro IPC failed: {err:?}");
diff --git a/crates/proc-macro-srv/src/lib.rs b/crates/proc-macro-srv/src/lib.rs
index a6090253d3..99dfa24ca4 100644
--- a/crates/proc-macro-srv/src/lib.rs
+++ b/crates/proc-macro-srv/src/lib.rs
@@ -104,6 +104,11 @@ pub enum ProcMacroClientError {
Eof,
}
+#[derive(Debug)]
+pub struct ProcMacroCancelMarker {
+ pub reason: String,
+}
+
pub type ProcMacroClientHandle<'a> = &'a mut (dyn ProcMacroClientInterface + Sync + Send);
pub trait ProcMacroClientInterface {
@@ -153,7 +158,13 @@ impl ProcMacroSrv<'_> {
});
match thread.unwrap().join() {
Ok(res) => res,
- Err(e) => std::panic::resume_unwind(e),
+
+ Err(payload) => {
+ if let Some(cancel) = payload.downcast_ref::<ProcMacroCancelMarker>() {
+ return Err(PanicMessage { message: Some(cancel.reason.clone()) });
+ }
+ std::panic::resume_unwind(payload)
+ }
}
});
prev_env.rollback();