Skip to content

Commit

Permalink
Fix warnings in jsonrpc crate
Browse files Browse the repository at this point in the history
  • Loading branch information
efoerster committed May 30, 2019
1 parent 8afd836 commit 1a49194
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 22 deletions.
6 changes: 3 additions & 3 deletions jsonrpc/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct Client<O> {

impl<O> Client<O>
where
O: Sink<String> + Unpin + Send,
O: Output,
{
pub fn new(output: Arc<Mutex<O>>) -> Self {
Client {
Expand Down Expand Up @@ -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<O> ResponseHandler for Client<O>
where
O: Sink<String> + Unpin + Send,
O: Output,
{
fn handle(&self, response: Response) -> BoxFuture<'_, ()> {
let task = async move {
Expand Down
18 changes: 9 additions & 9 deletions jsonrpc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(await_macro, async_await)]
#![feature(await_macro, async_await, trait_alias)]

pub mod client;
pub mod server;
Expand All @@ -25,11 +25,11 @@ pub struct MessageHandler<S, C, I, O> {
}

impl<S, C, I, O> MessageHandler<S, C, I, O>
where
S: RequestHandler + ActionHandler + Send + Sync + 'static,
C: ResponseHandler + Send + Sync + 'static,
I: Stream<Item = std::io::Result<String>> + Unpin,
O: Sink<String> + 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()) {
Expand All @@ -47,7 +47,7 @@ impl<S, C, I, O> MessageHandler<S, C, I, O>
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());
};

Expand All @@ -70,9 +70,9 @@ impl<S, C, I, O> MessageHandler<S, C, I, O>
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();
}
}
}
}
}
}
7 changes: 3 additions & 4 deletions jsonrpc/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
6 changes: 6 additions & 0 deletions jsonrpc/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
use futures::prelude::*;
use serde::{Deserialize, Serialize};
use serde_repr::*;
use std::io;

pub trait Input = Stream<Item = io::Result<String>> + Unpin;

pub trait Output = Sink<String, SinkError = io::Error> + Unpin + Send;

pub const PROTOCOL_VERSION: &str = "2.0";

Expand Down
6 changes: 3 additions & 3 deletions jsonrpc_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub fn jsonrpc_client(

impl<O> #struct_ident<O>
where
O: futures::Sink<String> + Unpin + Send,
O: jsonrpc::Output,
{
pub fn new(output: std::sync::Arc<futures::lock::Mutex<O>>) -> Self {
Self {
Expand All @@ -133,14 +133,14 @@ pub fn jsonrpc_client(

impl<O> #trait_ident for #struct_ident<O>
where
O: futures::Sink<String> + Unpin + Send,
O: jsonrpc::Output,
{
#(#stubs)*
}

impl<O> jsonrpc::ResponseHandler for #struct_ident<O>
where
O: futures::Sink<String> + Unpin + Send,
O: jsonrpc::Output,
{
fn handle(&self, response: jsonrpc::Response) -> futures::future::BoxFuture<'_, ()> {
self.client.handle(response)
Expand Down
8 changes: 5 additions & 3 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<C> {
client: Arc<C>,
Expand Down Expand Up @@ -140,7 +140,8 @@ impl<C: LspClient + Send + Sync> LatexLspServer<C> {
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);
Expand All @@ -165,7 +166,8 @@ impl<C: LspClient + Send + Sync> LatexLspServer<C> {

#[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);
}

Expand Down

0 comments on commit 1a49194

Please sign in to comment.