diff options
| author | Lukas Wirth <lukastw97@gmail.com> | 2024-12-26 15:42:53 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-26 15:42:53 +0000 |
| commit | 352116ce9734c24e41ff10524a7b72b3536d9c63 (patch) | |
| tree | ed4ee9ebebddc3cfcbf192eebc35e2fda31937d5 | |
| parent | bae8fb5c8074d2fb478b6f124dacf4b8b5f42d62 (diff) | |
| parent | 637700e974e04ac15a6c3fbc134129182aa1b847 (diff) | |
| download | rust-352116ce9734c24e41ff10524a7b72b3536d9c63.tar.gz rust-352116ce9734c24e41ff10524a7b72b3536d9c63.zip | |
Merge pull request #18762 from davidbarsky/davidbarsky/wrap-salsa-cancellation-error
internal: wrap `salsa::Cycle`
| -rw-r--r-- | src/tools/rust-analyzer/crates/ra-salsa/src/lib.rs | 2 | ||||
| -rw-r--r-- | src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/dispatch.rs | 31 |
2 files changed, 28 insertions, 5 deletions
diff --git a/src/tools/rust-analyzer/crates/ra-salsa/src/lib.rs b/src/tools/rust-analyzer/crates/ra-salsa/src/lib.rs index 6e43676354c..8530521d915 100644 --- a/src/tools/rust-analyzer/crates/ra-salsa/src/lib.rs +++ b/src/tools/rust-analyzer/crates/ra-salsa/src/lib.rs @@ -610,9 +610,11 @@ where #[non_exhaustive] pub enum Cancelled { /// The query was operating on revision R, but there is a pending write to move to revision R+1. + #[non_exhaustive] PendingWrite, /// The query was blocked on another thread, and that thread panicked. + #[non_exhaustive] PropagatedPanic, } diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/dispatch.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/dispatch.rs index 148a8194cda..ff50f7533a6 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/dispatch.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/dispatch.rs @@ -308,10 +308,31 @@ impl RequestDispatcher<'_> { } } +#[derive(Debug)] +enum HandlerCancelledError { + PropagatedPanic, + Inner(ide::Cancelled), +} + +impl std::error::Error for HandlerCancelledError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + HandlerCancelledError::PropagatedPanic => None, + HandlerCancelledError::Inner(cancelled) => Some(cancelled), + } + } +} + +impl fmt::Display for HandlerCancelledError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "Cancelled") + } +} + fn thread_result_to_response<R>( id: lsp_server::RequestId, result: thread::Result<anyhow::Result<R::Result>>, -) -> Result<lsp_server::Response, Cancelled> +) -> Result<lsp_server::Response, HandlerCancelledError> where R: lsp_types::request::Request, R::Params: DeserializeOwned, @@ -331,10 +352,10 @@ where message.push_str(panic_message) } else if let Some(cycle) = panic.downcast_ref::<Cycle>() { tracing::error!("Cycle propagated out of salsa! This is a bug: {cycle:?}"); - return Err(Cancelled::PropagatedPanic); + return Err(HandlerCancelledError::PropagatedPanic); } else if let Ok(cancelled) = panic.downcast::<Cancelled>() { tracing::error!("Cancellation propagated out of salsa! This is a bug"); - return Err(*cancelled); + return Err(HandlerCancelledError::Inner(*cancelled)); } Ok(lsp_server::Response::new_err( @@ -349,7 +370,7 @@ where fn result_to_response<R>( id: lsp_server::RequestId, result: anyhow::Result<R::Result>, -) -> Result<lsp_server::Response, Cancelled> +) -> Result<lsp_server::Response, HandlerCancelledError> where R: lsp_types::request::Request, R::Params: DeserializeOwned, @@ -360,7 +381,7 @@ where Err(e) => match e.downcast::<LspError>() { Ok(lsp_error) => lsp_server::Response::new_err(id, lsp_error.code, lsp_error.message), Err(e) => match e.downcast::<Cancelled>() { - Ok(cancelled) => return Err(cancelled), + Ok(cancelled) => return Err(HandlerCancelledError::Inner(cancelled)), Err(e) => lsp_server::Response::new_err( id, lsp_server::ErrorCode::InternalError as i32, |
