Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
address PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
leops committed Sep 5, 2022
1 parent 471c0ae commit efae848
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
15 changes: 15 additions & 0 deletions crates/rome_cli/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@ type JsonRpcResult = Result<Box<RawValue>, 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<Vec<u8>>,
Expand Down
14 changes: 8 additions & 6 deletions crates/rome_lsp/src/server.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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)),
},
}
})
},
Expand Down

0 comments on commit efae848

Please sign in to comment.