diff --git a/crates/rome_cli/src/service/mod.rs b/crates/rome_cli/src/service/mod.rs index 21442a7b3a46..91ef76955878 100644 --- a/crates/rome_cli/src/service/mod.rs +++ b/crates/rome_cli/src/service/mod.rs @@ -67,6 +67,21 @@ type JsonRpcResult = Result, TransportError>; /// Implementation of [WorkspaceTransport] for types implementing [AsyncRead] /// and [AsyncWrite] +/// +/// This implementation makes use of two "background tasks": +/// - the "write task" pulls outgoing messages from the "write channel" and +/// writes them to the "write half" of the socket +/// - the "read task" reads incoming messages from the "read half" of the +/// socket, then looks up a request with an ID corresponding to the received +/// message in the "pending requests" map. If a pending request is found, it's +/// fullfilled with the content of the message that was just received +/// +/// In addition to these, a new "foreground task" is created for each request. +/// These tasks create a "oneshot channel" and store it in the pending requests +/// map using the request ID as a key, then serialize the content of the +/// request and send it over the write channel. Finally, the task blocks the +/// current thread until a response is received over the oneshot channel from +/// the read task, or the request times out pub struct SocketTransport { runtime: Runtime, write_send: Sender>, diff --git a/crates/rome_lsp/src/server.rs b/crates/rome_lsp/src/server.rs index 43f7ded2986f..5dc06a8c19e5 100644 --- a/crates/rome_lsp/src/server.rs +++ b/crates/rome_lsp/src/server.rs @@ -1,4 +1,4 @@ -use std::{panic::catch_unwind, sync::Arc}; +use std::sync::Arc; use crate::capabilities::server_capabilities; use crate::requests::syntax_tree::{SyntaxTreePayload, SYNTAX_TREE_REQUEST}; @@ -185,15 +185,17 @@ macro_rules! workspace_method { let workspace = server.session.workspace.clone(); let result = spawn_blocking(move || { let _guard = span.entered(); - catch_unwind(move || workspace.$method(params)) + workspace.$method(params) }); result.map(move |result| { match result { - Ok(Ok(Ok(result))) => Ok(result), - Ok(Ok(Err(err))) => Err(into_lsp_error(err)), - Ok(Err(err)) => Err(panic_to_lsp_error(err)), - Err(err) => Err(into_lsp_error(err)), + Ok(Ok(result)) => Ok(result), + Ok(Err(err)) => Err(into_lsp_error(err)), + Err(err) => match err.try_into_panic() { + Ok(err) => Err(panic_to_lsp_error(err)), + Err(err) => Err(into_lsp_error(err)), + }, } }) },