diff --git a/jsonrpc/src/client.rs b/jsonrpc/src/client.rs index fd8305c58..7db337871 100644 --- a/jsonrpc/src/client.rs +++ b/jsonrpc/src/client.rs @@ -25,7 +25,7 @@ pub struct Client { impl Client where - O: Sink + Unpin + Send, + O: Output, { pub fn new(output: Arc>) -> Self { Client { @@ -61,13 +61,13 @@ where async fn send(&self, message: Message) { let json = serde_json::to_string(&message).unwrap(); let mut output = await!(self.output.lock()); - await!(output.send(json)); + await!(output.send(json)).unwrap(); } } impl ResponseHandler for Client where - O: Sink + Unpin + Send, + O: Output, { fn handle(&self, response: Response) -> BoxFuture<'_, ()> { let task = async move { diff --git a/jsonrpc/src/lib.rs b/jsonrpc/src/lib.rs index 7118830d7..ece4258c5 100644 --- a/jsonrpc/src/lib.rs +++ b/jsonrpc/src/lib.rs @@ -1,4 +1,4 @@ -#![feature(await_macro, async_await)] +#![feature(await_macro, async_await, trait_alias)] pub mod client; pub mod server; @@ -25,11 +25,11 @@ pub struct MessageHandler { } impl MessageHandler - where - S: RequestHandler + ActionHandler + Send + Sync + 'static, - C: ResponseHandler + Send + Sync + 'static, - I: Stream> + Unpin, - O: Sink + Unpin + Send + 'static, +where + S: RequestHandler + ActionHandler + Send + Sync + 'static, + C: ResponseHandler + Send + Sync + 'static, + I: Input, + O: Output + 'static, { pub async fn listen(&mut self) { while let Some(json) = await!(self.input.next()) { @@ -47,7 +47,7 @@ impl MessageHandler let response = await!(server.handle_request(request)); let json = serde_json::to_string(&response).unwrap(); let mut output = await!(output.lock()); - await!(output.send(json)); + await!(output.send(json)).unwrap(); await!(server.execute_actions()); }; @@ -70,9 +70,9 @@ impl MessageHandler let response = Response::error(why, None); let json = serde_json::to_string(&response).unwrap(); let mut output = await!(self.output.lock()); - await!(output.send(json)); + await!(output.send(json)).unwrap(); } } } } -} \ No newline at end of file +} diff --git a/jsonrpc/src/server.rs b/jsonrpc/src/server.rs index 4158e3a9e..fe1bfd640 100644 --- a/jsonrpc/src/server.rs +++ b/jsonrpc/src/server.rs @@ -41,10 +41,9 @@ where H: Fn(I) -> () + Send + Sync + 'a, I: DeserializeOwned + Send, { - match serde_json::from_value(notification.params) { - Ok(params) => handler(params), - Err(_) => panic!(Error::deserialize_error().message), - } + let params = + serde_json::from_value(notification.params).expect(&Error::deserialize_error().message); + handler(params); } #[cfg(test)] diff --git a/jsonrpc/src/types.rs b/jsonrpc/src/types.rs index 0e73f356f..b42a9f832 100644 --- a/jsonrpc/src/types.rs +++ b/jsonrpc/src/types.rs @@ -1,5 +1,11 @@ +use futures::prelude::*; use serde::{Deserialize, Serialize}; use serde_repr::*; +use std::io; + +pub trait Input = Stream> + Unpin; + +pub trait Output = Sink + Unpin + Send; pub const PROTOCOL_VERSION: &str = "2.0"; diff --git a/jsonrpc_derive/src/lib.rs b/jsonrpc_derive/src/lib.rs index cdacbc7b8..e8c3318a5 100644 --- a/jsonrpc_derive/src/lib.rs +++ b/jsonrpc_derive/src/lib.rs @@ -122,7 +122,7 @@ pub fn jsonrpc_client( impl #struct_ident where - O: futures::Sink + Unpin + Send, + O: jsonrpc::Output, { pub fn new(output: std::sync::Arc>) -> Self { Self { @@ -133,14 +133,14 @@ pub fn jsonrpc_client( impl #trait_ident for #struct_ident where - O: futures::Sink + Unpin + Send, + O: jsonrpc::Output, { #(#stubs)* } impl jsonrpc::ResponseHandler for #struct_ident where - O: futures::Sink + Unpin + Send, + O: jsonrpc::Output, { fn handle(&self, response: jsonrpc::Response) -> futures::future::BoxFuture<'_, ()> { self.client.handle(response) diff --git a/src/server.rs b/src/server.rs index de0a07e9f..1db07c888 100644 --- a/src/server.rs +++ b/src/server.rs @@ -29,10 +29,10 @@ use log::*; use lsp_types::*; use serde::de::DeserializeOwned; use std::borrow::Cow; +use std::fs; use std::path::PathBuf; use std::sync::Arc; use walkdir::WalkDir; -use std::fs; pub struct LatexLspServer { client: Arc, @@ -140,7 +140,8 @@ impl LatexLspServer { let tex_path = PathBuf::from(format!("{}tex", &name[0..name.len() - 3])); let tex_uri = Uri::from_file_path(tex_path).unwrap(); if workspace.find(&tex_uri).is_some() { - self.action_manager.push(Action::ParseLog {tex_uri, log_path}); + self.action_manager + .push(Action::ParseLog { tex_uri, log_path }); } } self.action_manager.push(Action::PublishDiagnostics); @@ -165,7 +166,8 @@ impl LatexLspServer { #[jsonrpc_method("textDocument/didSave", kind = "notification")] pub fn did_save(&self, params: DidSaveTextDocumentParams) { - self.action_manager.push(Action::RunLinter(params.text_document.uri)); + self.action_manager + .push(Action::RunLinter(params.text_document.uri)); self.action_manager.push(Action::PublishDiagnostics); }