From 38cb934d8f579663ff13496bf79293103863b60b Mon Sep 17 00:00:00 2001 From: wojciechkepka Date: Fri, 18 Jun 2021 05:42:34 +0200 Subject: Add unique id to each lsp client/server pair --- helix-lsp/src/transport.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'helix-lsp/src/transport.rs') diff --git a/helix-lsp/src/transport.rs b/helix-lsp/src/transport.rs index e8068323..29ce2e84 100644 --- a/helix-lsp/src/transport.rs +++ b/helix-lsp/src/transport.rs @@ -33,7 +33,8 @@ enum ServerMessage { #[derive(Debug)] pub struct Transport { - client_tx: UnboundedSender, + id: usize, + client_tx: UnboundedSender<(usize, jsonrpc::Call)>, client_rx: UnboundedReceiver, pending_requests: HashMap>>, @@ -48,11 +49,16 @@ impl Transport { server_stdout: BufReader, server_stdin: BufWriter, server_stderr: BufReader, - ) -> (UnboundedReceiver, UnboundedSender) { + id: usize, + ) -> ( + UnboundedReceiver<(usize, jsonrpc::Call)>, + UnboundedSender, + ) { let (client_tx, rx) = unbounded_channel(); let (tx, client_rx) = unbounded_channel(); let transport = Self { + id, server_stdout, server_stdin, server_stderr, @@ -156,7 +162,7 @@ impl Transport { match msg { ServerMessage::Output(output) => self.process_request_response(output).await?, ServerMessage::Call(call) => { - self.client_tx.send(call).unwrap(); + self.client_tx.send((self.id, call)).unwrap(); // let notification = Notification::parse(&method, params); } }; -- cgit v1.2.3-70-g09d2 From dd0af78079342b46ae1f4d1b265c7e0cd7519631 Mon Sep 17 00:00:00 2001 From: wojciechkepka Date: Sat, 19 Jun 2021 04:57:05 +0200 Subject: Fix unwraps in lsp::transport --- helix-lsp/src/transport.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'helix-lsp/src/transport.rs') diff --git a/helix-lsp/src/transport.rs b/helix-lsp/src/transport.rs index 29ce2e84..df55bbf6 100644 --- a/helix-lsp/src/transport.rs +++ b/helix-lsp/src/transport.rs @@ -1,4 +1,5 @@ use crate::Result; +use anyhow::Context; use jsonrpc_core as jsonrpc; use log::{error, info}; use serde::{Deserialize, Serialize}; @@ -90,7 +91,7 @@ impl Transport { match (parts.next(), parts.next(), parts.next()) { (Some("Content-Length"), Some(value), None) => { - content_length = Some(value.parse().unwrap()); + content_length = Some(value.parse().context("invalid content length")?); } (Some(_), Some(_), None) => {} _ => { @@ -103,12 +104,12 @@ impl Transport { } } - let content_length = content_length.unwrap(); + let content_length = content_length.context("missing content length")?; //TODO: reuse vector let mut content = vec![0; content_length]; reader.read_exact(&mut content).await?; - let msg = String::from_utf8(content).unwrap(); + let msg = String::from_utf8(content).context("invalid utf8 from server")?; info!("<- {}", msg); @@ -162,7 +163,9 @@ impl Transport { match msg { ServerMessage::Output(output) => self.process_request_response(output).await?, ServerMessage::Call(call) => { - self.client_tx.send((self.id, call)).unwrap(); + self.client_tx + .send((self.id, call)) + .context("failed to send a message to server")?; // let notification = Notification::parse(&method, params); } }; -- cgit v1.2.3-70-g09d2