diff options
author | Aleksey Kladov <[email protected]> | 2019-02-08 11:49:43 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-02-08 11:49:43 +0000 |
commit | 12e3b4c70b5ef23b2fdfc197296d483680e125f9 (patch) | |
tree | 71baa0e0a62f9f6b61450501c5f821f67badf9e4 /crates/gen_lsp_server | |
parent | 5cb1d41a30d25cbe136402644bf5434dd667f1e5 (diff) |
reformat the world
Diffstat (limited to 'crates/gen_lsp_server')
-rw-r--r-- | crates/gen_lsp_server/src/msg.rs | 39 | ||||
-rw-r--r-- | crates/gen_lsp_server/src/stdio.rs | 4 |
2 files changed, 9 insertions, 34 deletions
diff --git a/crates/gen_lsp_server/src/msg.rs b/crates/gen_lsp_server/src/msg.rs index 818111fe7..02c7a1858 100644 --- a/crates/gen_lsp_server/src/msg.rs +++ b/crates/gen_lsp_server/src/msg.rs | |||
@@ -80,10 +80,7 @@ impl RawMessage { | |||
80 | #[serde(flatten)] | 80 | #[serde(flatten)] |
81 | msg: RawMessage, | 81 | msg: RawMessage, |
82 | } | 82 | } |
83 | let text = to_string(&JsonRpc { | 83 | let text = to_string(&JsonRpc { jsonrpc: "2.0", msg: self })?; |
84 | jsonrpc: "2.0", | ||
85 | msg: self, | ||
86 | })?; | ||
87 | write_msg_text(w, &text)?; | 84 | write_msg_text(w, &text)?; |
88 | Ok(()) | 85 | Ok(()) |
89 | } | 86 | } |
@@ -95,11 +92,7 @@ impl RawRequest { | |||
95 | R: Request, | 92 | R: Request, |
96 | R::Params: serde::Serialize, | 93 | R::Params: serde::Serialize, |
97 | { | 94 | { |
98 | RawRequest { | 95 | RawRequest { id, method: R::METHOD.to_string(), params: to_value(params).unwrap() } |
99 | id, | ||
100 | method: R::METHOD.to_string(), | ||
101 | params: to_value(params).unwrap(), | ||
102 | } | ||
103 | } | 96 | } |
104 | pub fn cast<R>(self) -> ::std::result::Result<(u64, R::Params), RawRequest> | 97 | pub fn cast<R>(self) -> ::std::result::Result<(u64, R::Params), RawRequest> |
105 | where | 98 | where |
@@ -121,23 +114,11 @@ impl RawResponse { | |||
121 | R: Request, | 114 | R: Request, |
122 | R::Result: serde::Serialize, | 115 | R::Result: serde::Serialize, |
123 | { | 116 | { |
124 | RawResponse { | 117 | RawResponse { id, result: Some(to_value(&result).unwrap()), error: None } |
125 | id, | ||
126 | result: Some(to_value(&result).unwrap()), | ||
127 | error: None, | ||
128 | } | ||
129 | } | 118 | } |
130 | pub fn err(id: u64, code: i32, message: String) -> RawResponse { | 119 | pub fn err(id: u64, code: i32, message: String) -> RawResponse { |
131 | let error = RawResponseError { | 120 | let error = RawResponseError { code, message, data: None }; |
132 | code, | 121 | RawResponse { id, result: None, error: Some(error) } |
133 | message, | ||
134 | data: None, | ||
135 | }; | ||
136 | RawResponse { | ||
137 | id, | ||
138 | result: None, | ||
139 | error: Some(error), | ||
140 | } | ||
141 | } | 122 | } |
142 | } | 123 | } |
143 | 124 | ||
@@ -147,10 +128,7 @@ impl RawNotification { | |||
147 | N: Notification, | 128 | N: Notification, |
148 | N::Params: serde::Serialize, | 129 | N::Params: serde::Serialize, |
149 | { | 130 | { |
150 | RawNotification { | 131 | RawNotification { method: N::METHOD.to_string(), params: to_value(params).unwrap() } |
151 | method: N::METHOD.to_string(), | ||
152 | params: to_value(params).unwrap(), | ||
153 | } | ||
154 | } | 132 | } |
155 | pub fn is<N>(&self) -> bool | 133 | pub fn is<N>(&self) -> bool |
156 | where | 134 | where |
@@ -187,9 +165,8 @@ fn read_msg_text(inp: &mut impl BufRead) -> Result<Option<String>> { | |||
187 | } | 165 | } |
188 | let mut parts = buf.splitn(2, ": "); | 166 | let mut parts = buf.splitn(2, ": "); |
189 | let header_name = parts.next().unwrap(); | 167 | let header_name = parts.next().unwrap(); |
190 | let header_value = parts | 168 | let header_value = |
191 | .next() | 169 | parts.next().ok_or_else(|| format_err!("malformed header: {:?}", buf))?; |
192 | .ok_or_else(|| format_err!("malformed header: {:?}", buf))?; | ||
193 | if header_name == "Content-Length" { | 170 | if header_name == "Content-Length" { |
194 | size = Some(header_value.parse::<usize>()?); | 171 | size = Some(header_value.parse::<usize>()?); |
195 | } | 172 | } |
diff --git a/crates/gen_lsp_server/src/stdio.rs b/crates/gen_lsp_server/src/stdio.rs index 5c8e33854..dab2d8da8 100644 --- a/crates/gen_lsp_server/src/stdio.rs +++ b/crates/gen_lsp_server/src/stdio.rs | |||
@@ -13,9 +13,7 @@ pub fn stdio_transport() -> (Receiver<RawMessage>, Sender<RawMessage>, Threads) | |||
13 | let writer = thread::spawn(move || { | 13 | let writer = thread::spawn(move || { |
14 | let stdout = stdout(); | 14 | let stdout = stdout(); |
15 | let mut stdout = stdout.lock(); | 15 | let mut stdout = stdout.lock(); |
16 | writer_receiver | 16 | writer_receiver.into_iter().try_for_each(|it| it.write(&mut stdout))?; |
17 | .into_iter() | ||
18 | .try_for_each(|it| it.write(&mut stdout))?; | ||
19 | Ok(()) | 17 | Ok(()) |
20 | }); | 18 | }); |
21 | let (reader_sender, reader_receiver) = bounded::<RawMessage>(16); | 19 | let (reader_sender, reader_receiver) = bounded::<RawMessage>(16); |