diff options
author | Jeremy A. Kolb <[email protected]> | 2018-10-15 22:44:23 +0100 |
---|---|---|
committer | Jeremy A. Kolb <[email protected]> | 2018-10-16 14:41:10 +0100 |
commit | 61f3a438d3a729a6be941bca1ff4c6a97a33f221 (patch) | |
tree | 6551967cc8c6e921b66071453ad7888a9121d326 /crates/gen_lsp_server/src | |
parent | 39cb6c6d3f78b193f5873c3492e530bbd24d5dd2 (diff) |
Cargo Format
Run `cargo fmt` and ignore generated files
Diffstat (limited to 'crates/gen_lsp_server/src')
-rw-r--r-- | crates/gen_lsp_server/src/lib.rs | 35 | ||||
-rw-r--r-- | crates/gen_lsp_server/src/msg.rs | 29 | ||||
-rw-r--r-- | crates/gen_lsp_server/src/stdio.rs | 6 |
3 files changed, 33 insertions, 37 deletions
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 @@ | |||
59 | //! } | 59 | //! } |
60 | //! ``` | 60 | //! ``` |
61 | 61 | ||
62 | |||
63 | #[macro_use] | 62 | #[macro_use] |
64 | extern crate failure; | 63 | extern crate failure; |
65 | #[macro_use] | 64 | #[macro_use] |
@@ -74,16 +73,16 @@ extern crate languageserver_types; | |||
74 | mod msg; | 73 | mod msg; |
75 | mod stdio; | 74 | mod stdio; |
76 | 75 | ||
77 | use crossbeam_channel::{Sender, Receiver}; | 76 | use crossbeam_channel::{Receiver, Sender}; |
78 | use languageserver_types::{ | 77 | use languageserver_types::{ |
79 | ServerCapabilities, InitializeResult, InitializeParams, | 78 | notification::{Exit, Initialized}, |
80 | request::{Initialize, Shutdown}, | 79 | request::{Initialize, Shutdown}, |
81 | notification::{Initialized, Exit}, | 80 | InitializeParams, InitializeResult, ServerCapabilities, |
82 | }; | 81 | }; |
83 | 82 | ||
84 | pub type Result<T> = ::std::result::Result<T, failure::Error>; | 83 | pub type Result<T> = ::std::result::Result<T, failure::Error>; |
85 | pub use { | 84 | pub use { |
86 | msg::{RawMessage, RawRequest, RawResponse, RawResponseError, RawNotification, ErrorCode}, | 85 | msg::{ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse, RawResponseError}, |
87 | stdio::{stdio_transport, Threads}, | 86 | stdio::{stdio_transport, Threads}, |
88 | }; | 87 | }; |
89 | 88 | ||
@@ -97,11 +96,7 @@ pub fn run_server( | |||
97 | caps: ServerCapabilities, | 96 | caps: ServerCapabilities, |
98 | receiver: Receiver<RawMessage>, | 97 | receiver: Receiver<RawMessage>, |
99 | sender: Sender<RawMessage>, | 98 | sender: Sender<RawMessage>, |
100 | server: impl FnOnce( | 99 | server: impl FnOnce(InitializeParams, &Receiver<RawMessage>, &Sender<RawMessage>) -> Result<()>, |
101 | InitializeParams, | ||
102 | &Receiver<RawMessage>, | ||
103 | &Sender<RawMessage>, | ||
104 | ) -> Result<()>, | ||
105 | ) -> Result<()> { | 100 | ) -> Result<()> { |
106 | info!("lsp server initializes"); | 101 | info!("lsp server initializes"); |
107 | let params = initialize(&receiver, &sender, caps)?; | 102 | let params = initialize(&receiver, &sender, caps)?; |
@@ -109,12 +104,10 @@ pub fn run_server( | |||
109 | server(params, &receiver, &sender)?; | 104 | server(params, &receiver, &sender)?; |
110 | info!("lsp server waiting for exit notification"); | 105 | info!("lsp server waiting for exit notification"); |
111 | match receiver.recv() { | 106 | match receiver.recv() { |
112 | Some(RawMessage::Notification(n)) => { | 107 | Some(RawMessage::Notification(n)) => n |
113 | n.cast::<Exit>().map_err(|n| format_err!( | 108 | .cast::<Exit>() |
114 | "unexpected notification during shutdown: {:?}", n | 109 | .map_err(|n| format_err!("unexpected notification during shutdown: {:?}", n))?, |
115 | ))? | 110 | m => bail!("unexpected message during shutdown: {:?}", m), |
116 | } | ||
117 | m => bail!("unexpected message during shutdown: {:?}", m) | ||
118 | } | 111 | } |
119 | info!("lsp server shutdown complete"); | 112 | info!("lsp server shutdown complete"); |
120 | Ok(()) | 113 | Ok(()) |
@@ -141,17 +134,15 @@ fn initialize( | |||
141 | Some(RawMessage::Request(req)) => match req.cast::<Initialize>() { | 134 | Some(RawMessage::Request(req)) => match req.cast::<Initialize>() { |
142 | Err(req) => bail!("expected initialize request, got {:?}", req), | 135 | Err(req) => bail!("expected initialize request, got {:?}", req), |
143 | Ok(req) => req, | 136 | Ok(req) => req, |
144 | } | 137 | }, |
145 | msg => | 138 | msg => bail!("expected initialize request, got {:?}", msg), |
146 | bail!("expected initialize request, got {:?}", msg), | ||
147 | }; | 139 | }; |
148 | let resp = RawResponse::ok::<Initialize>(id, &InitializeResult { capabilities: caps }); | 140 | let resp = RawResponse::ok::<Initialize>(id, &InitializeResult { capabilities: caps }); |
149 | sender.send(RawMessage::Response(resp)); | 141 | sender.send(RawMessage::Response(resp)); |
150 | match receiver.recv() { | 142 | match receiver.recv() { |
151 | Some(RawMessage::Notification(n)) => { | 143 | Some(RawMessage::Notification(n)) => { |
152 | n.cast::<Initialized>().map_err(|_| format_err!( | 144 | n.cast::<Initialized>() |
153 | "expected initialized notification" | 145 | .map_err(|_| format_err!("expected initialized notification"))?; |
154 | ))?; | ||
155 | } | 146 | } |
156 | _ => bail!("expected initialized notification"), | 147 | _ => bail!("expected initialized notification"), |
157 | } | 148 | } |
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 @@ | |||
1 | use std::io::{BufRead, Write}; | 1 | use std::io::{BufRead, Write}; |
2 | 2 | ||
3 | use serde_json::{Value, from_str, to_string, from_value, to_value}; | 3 | use languageserver_types::{notification::Notification, request::Request}; |
4 | use serde::{Serialize, de::DeserializeOwned}; | 4 | use serde::{de::DeserializeOwned, Serialize}; |
5 | use languageserver_types::{ | 5 | use serde_json::{from_str, from_value, to_string, to_value, Value}; |
6 | request::Request, | ||
7 | notification::Notification, | ||
8 | }; | ||
9 | 6 | ||
10 | use Result; | 7 | use Result; |
11 | 8 | ||
@@ -81,7 +78,10 @@ impl RawMessage { | |||
81 | #[serde(flatten)] | 78 | #[serde(flatten)] |
82 | msg: RawMessage, | 79 | msg: RawMessage, |
83 | } | 80 | } |
84 | let text = to_string(&JsonRpc { jsonrpc: "2.0", msg: self })?; | 81 | let text = to_string(&JsonRpc { |
82 | jsonrpc: "2.0", | ||
83 | msg: self, | ||
84 | })?; | ||
85 | write_msg_text(w, &text)?; | 85 | write_msg_text(w, &text)?; |
86 | Ok(()) | 86 | Ok(()) |
87 | } | 87 | } |
@@ -115,8 +115,9 @@ impl RawRequest { | |||
115 | 115 | ||
116 | impl RawResponse { | 116 | impl RawResponse { |
117 | pub fn ok<R>(id: u64, result: &R::Result) -> RawResponse | 117 | pub fn ok<R>(id: u64, result: &R::Result) -> RawResponse |
118 | where R: Request, | 118 | where |
119 | R::Result: Serialize, | 119 | R: Request, |
120 | R::Result: Serialize, | ||
120 | { | 121 | { |
121 | RawResponse { | 122 | RawResponse { |
122 | id, | 123 | id, |
@@ -125,7 +126,11 @@ impl RawResponse { | |||
125 | } | 126 | } |
126 | } | 127 | } |
127 | pub fn err(id: u64, code: i32, message: String) -> RawResponse { | 128 | pub fn err(id: u64, code: i32, message: String) -> RawResponse { |
128 | let error = RawResponseError { code, message, data: None }; | 129 | let error = RawResponseError { |
130 | code, | ||
131 | message, | ||
132 | data: None, | ||
133 | }; | ||
129 | RawResponse { | 134 | RawResponse { |
130 | id, | 135 | id, |
131 | result: None, | 136 | result: None, |
@@ -174,7 +179,9 @@ fn read_msg_text(inp: &mut impl BufRead) -> Result<Option<String>> { | |||
174 | } | 179 | } |
175 | let mut parts = buf.splitn(2, ": "); | 180 | let mut parts = buf.splitn(2, ": "); |
176 | let header_name = parts.next().unwrap(); | 181 | let header_name = parts.next().unwrap(); |
177 | let header_value = parts.next().ok_or_else(|| format_err!("malformed header: {:?}", buf))?; | 182 | let header_value = parts |
183 | .next() | ||
184 | .ok_or_else(|| format_err!("malformed header: {:?}", buf))?; | ||
178 | if header_name == "Content-Length" { | 185 | if header_name == "Content-Length" { |
179 | size = Some(header_value.parse::<usize>()?); | 186 | size = Some(header_value.parse::<usize>()?); |
180 | } | 187 | } |
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 @@ | |||
1 | use std::{ | 1 | use std::{ |
2 | io::{stdin, stdout}, | ||
2 | thread, | 3 | thread, |
3 | io::{ | ||
4 | stdout, stdin, | ||
5 | }, | ||
6 | }; | 4 | }; |
7 | 5 | ||
8 | use crossbeam_channel::{Receiver, Sender, bounded}; | 6 | use crossbeam_channel::{bounded, Receiver, Sender}; |
9 | 7 | ||
10 | use {RawMessage, Result}; | 8 | use {RawMessage, Result}; |
11 | 9 | ||