From 61f3a438d3a729a6be941bca1ff4c6a97a33f221 Mon Sep 17 00:00:00 2001 From: "Jeremy A. Kolb" Date: Mon, 15 Oct 2018 17:44:23 -0400 Subject: Cargo Format Run `cargo fmt` and ignore generated files --- crates/gen_lsp_server/src/lib.rs | 35 +++++++++++++---------------------- crates/gen_lsp_server/src/msg.rs | 29 ++++++++++++++++++----------- crates/gen_lsp_server/src/stdio.rs | 6 ++---- 3 files changed, 33 insertions(+), 37 deletions(-) (limited to 'crates/gen_lsp_server/src') diff --git a/crates/gen_lsp_server/src/lib.rs b/crates/gen_lsp_server/src/lib.rs index 645728a57..e45a6b5e2 100644 --- a/crates/gen_lsp_server/src/lib.rs +++ b/crates/gen_lsp_server/src/lib.rs @@ -59,7 +59,6 @@ //! } //! ``` - #[macro_use] extern crate failure; #[macro_use] @@ -74,16 +73,16 @@ extern crate languageserver_types; mod msg; mod stdio; -use crossbeam_channel::{Sender, Receiver}; +use crossbeam_channel::{Receiver, Sender}; use languageserver_types::{ - ServerCapabilities, InitializeResult, InitializeParams, + notification::{Exit, Initialized}, request::{Initialize, Shutdown}, - notification::{Initialized, Exit}, + InitializeParams, InitializeResult, ServerCapabilities, }; pub type Result = ::std::result::Result; pub use { - msg::{RawMessage, RawRequest, RawResponse, RawResponseError, RawNotification, ErrorCode}, + msg::{ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse, RawResponseError}, stdio::{stdio_transport, Threads}, }; @@ -97,11 +96,7 @@ pub fn run_server( caps: ServerCapabilities, receiver: Receiver, sender: Sender, - server: impl FnOnce( - InitializeParams, - &Receiver, - &Sender, - ) -> Result<()>, + server: impl FnOnce(InitializeParams, &Receiver, &Sender) -> Result<()>, ) -> Result<()> { info!("lsp server initializes"); let params = initialize(&receiver, &sender, caps)?; @@ -109,12 +104,10 @@ pub fn run_server( server(params, &receiver, &sender)?; info!("lsp server waiting for exit notification"); match receiver.recv() { - Some(RawMessage::Notification(n)) => { - n.cast::().map_err(|n| format_err!( - "unexpected notification during shutdown: {:?}", n - ))? - } - m => bail!("unexpected message during shutdown: {:?}", m) + Some(RawMessage::Notification(n)) => n + .cast::() + .map_err(|n| format_err!("unexpected notification during shutdown: {:?}", n))?, + m => bail!("unexpected message during shutdown: {:?}", m), } info!("lsp server shutdown complete"); Ok(()) @@ -141,17 +134,15 @@ fn initialize( Some(RawMessage::Request(req)) => match req.cast::() { Err(req) => bail!("expected initialize request, got {:?}", req), Ok(req) => req, - } - msg => - bail!("expected initialize request, got {:?}", msg), + }, + msg => bail!("expected initialize request, got {:?}", msg), }; let resp = RawResponse::ok::(id, &InitializeResult { capabilities: caps }); sender.send(RawMessage::Response(resp)); match receiver.recv() { Some(RawMessage::Notification(n)) => { - n.cast::().map_err(|_| format_err!( - "expected initialized notification" - ))?; + n.cast::() + .map_err(|_| format_err!("expected initialized notification"))?; } _ => bail!("expected initialized notification"), } diff --git a/crates/gen_lsp_server/src/msg.rs b/crates/gen_lsp_server/src/msg.rs index 7fcac6f6d..e0d0aeab5 100644 --- a/crates/gen_lsp_server/src/msg.rs +++ b/crates/gen_lsp_server/src/msg.rs @@ -1,11 +1,8 @@ use std::io::{BufRead, Write}; -use serde_json::{Value, from_str, to_string, from_value, to_value}; -use serde::{Serialize, de::DeserializeOwned}; -use languageserver_types::{ - request::Request, - notification::Notification, -}; +use languageserver_types::{notification::Notification, request::Request}; +use serde::{de::DeserializeOwned, Serialize}; +use serde_json::{from_str, from_value, to_string, to_value, Value}; use Result; @@ -81,7 +78,10 @@ impl RawMessage { #[serde(flatten)] msg: RawMessage, } - let text = to_string(&JsonRpc { jsonrpc: "2.0", msg: self })?; + let text = to_string(&JsonRpc { + jsonrpc: "2.0", + msg: self, + })?; write_msg_text(w, &text)?; Ok(()) } @@ -115,8 +115,9 @@ impl RawRequest { impl RawResponse { pub fn ok(id: u64, result: &R::Result) -> RawResponse - where R: Request, - R::Result: Serialize, + where + R: Request, + R::Result: Serialize, { RawResponse { id, @@ -125,7 +126,11 @@ impl RawResponse { } } pub fn err(id: u64, code: i32, message: String) -> RawResponse { - let error = RawResponseError { code, message, data: None }; + let error = RawResponseError { + code, + message, + data: None, + }; RawResponse { id, result: None, @@ -174,7 +179,9 @@ fn read_msg_text(inp: &mut impl BufRead) -> Result> { } let mut parts = buf.splitn(2, ": "); let header_name = parts.next().unwrap(); - let header_value = parts.next().ok_or_else(|| format_err!("malformed header: {:?}", buf))?; + let header_value = parts + .next() + .ok_or_else(|| format_err!("malformed header: {:?}", buf))?; if header_name == "Content-Length" { size = Some(header_value.parse::()?); } diff --git a/crates/gen_lsp_server/src/stdio.rs b/crates/gen_lsp_server/src/stdio.rs index 81397bb2a..3d8a1712a 100644 --- a/crates/gen_lsp_server/src/stdio.rs +++ b/crates/gen_lsp_server/src/stdio.rs @@ -1,11 +1,9 @@ use std::{ + io::{stdin, stdout}, thread, - io::{ - stdout, stdin, - }, }; -use crossbeam_channel::{Receiver, Sender, bounded}; +use crossbeam_channel::{bounded, Receiver, Sender}; use {RawMessage, Result}; -- cgit v1.2.3