diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/gen_lsp_server/src/msg.rs | 18 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop.rs | 19 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/req.rs | 3 |
3 files changed, 32 insertions, 8 deletions
diff --git a/crates/gen_lsp_server/src/msg.rs b/crates/gen_lsp_server/src/msg.rs index 02c7a1858..1d39ba4bc 100644 --- a/crates/gen_lsp_server/src/msg.rs +++ b/crates/gen_lsp_server/src/msg.rs | |||
@@ -15,6 +15,24 @@ pub enum RawMessage { | |||
15 | Response(RawResponse), | 15 | Response(RawResponse), |
16 | } | 16 | } |
17 | 17 | ||
18 | impl From<RawRequest> for RawMessage { | ||
19 | fn from(raw: RawRequest) -> RawMessage { | ||
20 | RawMessage::Request(raw) | ||
21 | } | ||
22 | } | ||
23 | |||
24 | impl From<RawNotification> for RawMessage { | ||
25 | fn from(raw: RawNotification) -> RawMessage { | ||
26 | RawMessage::Notification(raw) | ||
27 | } | ||
28 | } | ||
29 | |||
30 | impl From<RawResponse> for RawMessage { | ||
31 | fn from(raw: RawResponse) -> RawMessage { | ||
32 | RawMessage::Response(raw) | ||
33 | } | ||
34 | } | ||
35 | |||
18 | #[derive(Debug, Serialize, Deserialize, Clone)] | 36 | #[derive(Debug, Serialize, Deserialize, Clone)] |
19 | pub struct RawRequest { | 37 | pub struct RawRequest { |
20 | pub id: u64, | 38 | pub id: u64, |
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index ce50fb301..0f8ef10b9 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs | |||
@@ -63,6 +63,11 @@ pub fn main_loop( | |||
63 | Ok(ws) => vec![ws], | 63 | Ok(ws) => vec![ws], |
64 | Err(e) => { | 64 | Err(e) => { |
65 | log::error!("loading workspace failed: {}", e); | 65 | log::error!("loading workspace failed: {}", e); |
66 | let msg = RawNotification::new::<req::ShowMessage>(&req::ShowMessageParams { | ||
67 | typ: req::MessageType::Error, | ||
68 | message: format!("rust-analyzer failed to load workspace: {}", e), | ||
69 | }); | ||
70 | msg_sender.send(msg.into()).unwrap(); | ||
66 | Vec::new() | 71 | Vec::new() |
67 | } | 72 | } |
68 | } | 73 | } |
@@ -199,7 +204,7 @@ fn main_loop_inner( | |||
199 | Ok((id, ())) => { | 204 | Ok((id, ())) => { |
200 | state.collect_garbage(); | 205 | state.collect_garbage(); |
201 | let resp = RawResponse::ok::<req::CollectGarbage>(id, &()); | 206 | let resp = RawResponse::ok::<req::CollectGarbage>(id, &()); |
202 | msg_sender.send(RawMessage::Response(resp)).unwrap() | 207 | msg_sender.send(resp.into()).unwrap() |
203 | } | 208 | } |
204 | Err(req) => { | 209 | Err(req) => { |
205 | match on_request(state, pending_requests, pool, &task_sender, req)? { | 210 | match on_request(state, pending_requests, pool, &task_sender, req)? { |
@@ -211,7 +216,7 @@ fn main_loop_inner( | |||
211 | ErrorCode::MethodNotFound as i32, | 216 | ErrorCode::MethodNotFound as i32, |
212 | "unknown request".to_string(), | 217 | "unknown request".to_string(), |
213 | ); | 218 | ); |
214 | msg_sender.send(RawMessage::Response(resp)).unwrap() | 219 | msg_sender.send(resp.into()).unwrap() |
215 | } | 220 | } |
216 | } | 221 | } |
217 | } | 222 | } |
@@ -260,11 +265,11 @@ fn on_task(task: Task, msg_sender: &Sender<RawMessage>, pending_requests: &mut F | |||
260 | match task { | 265 | match task { |
261 | Task::Respond(response) => { | 266 | Task::Respond(response) => { |
262 | if pending_requests.remove(&response.id) { | 267 | if pending_requests.remove(&response.id) { |
263 | msg_sender.send(RawMessage::Response(response)).unwrap(); | 268 | msg_sender.send(response.into()).unwrap(); |
264 | } | 269 | } |
265 | } | 270 | } |
266 | Task::Notify(n) => { | 271 | Task::Notify(n) => { |
267 | msg_sender.send(RawMessage::Notification(n)).unwrap(); | 272 | msg_sender.send(n.into()).unwrap(); |
268 | } | 273 | } |
269 | } | 274 | } |
270 | } | 275 | } |
@@ -336,7 +341,7 @@ fn on_notification( | |||
336 | ErrorCode::RequestCanceled as i32, | 341 | ErrorCode::RequestCanceled as i32, |
337 | "canceled by client".to_string(), | 342 | "canceled by client".to_string(), |
338 | ); | 343 | ); |
339 | msg_sender.send(RawMessage::Response(response)).unwrap() | 344 | msg_sender.send(response.into()).unwrap() |
340 | } | 345 | } |
341 | return Ok(()); | 346 | return Ok(()); |
342 | } | 347 | } |
@@ -375,7 +380,7 @@ fn on_notification( | |||
375 | } | 380 | } |
376 | let params = req::PublishDiagnosticsParams { uri, diagnostics: Vec::new() }; | 381 | let params = req::PublishDiagnosticsParams { uri, diagnostics: Vec::new() }; |
377 | let not = RawNotification::new::<req::PublishDiagnostics>(¶ms); | 382 | let not = RawNotification::new::<req::PublishDiagnostics>(¶ms); |
378 | msg_sender.send(RawMessage::Notification(not)).unwrap(); | 383 | msg_sender.send(not.into()).unwrap(); |
379 | return Ok(()); | 384 | return Ok(()); |
380 | } | 385 | } |
381 | Err(not) => not, | 386 | Err(not) => not, |
@@ -501,7 +506,7 @@ fn feedback(intrnal_mode: bool, msg: &str, sender: &Sender<RawMessage>) { | |||
501 | return; | 506 | return; |
502 | } | 507 | } |
503 | let not = RawNotification::new::<req::InternalFeedback>(&msg.to_string()); | 508 | let not = RawNotification::new::<req::InternalFeedback>(&msg.to_string()); |
504 | sender.send(RawMessage::Notification(not)).unwrap(); | 509 | sender.send(not.into()).unwrap(); |
505 | } | 510 | } |
506 | 511 | ||
507 | fn is_canceled(e: &failure::Error) -> bool { | 512 | fn is_canceled(e: &failure::Error) -> bool { |
diff --git a/crates/ra_lsp_server/src/req.rs b/crates/ra_lsp_server/src/req.rs index 5c589f969..484fde7e5 100644 --- a/crates/ra_lsp_server/src/req.rs +++ b/crates/ra_lsp_server/src/req.rs | |||
@@ -8,7 +8,8 @@ pub use lsp_types::{ | |||
8 | CompletionParams, CompletionResponse, DocumentOnTypeFormattingParams, DocumentSymbolParams, | 8 | CompletionParams, CompletionResponse, DocumentOnTypeFormattingParams, DocumentSymbolParams, |
9 | DocumentSymbolResponse, ExecuteCommandParams, Hover, InitializeResult, | 9 | DocumentSymbolResponse, ExecuteCommandParams, Hover, InitializeResult, |
10 | PublishDiagnosticsParams, ReferenceParams, SignatureHelp, TextDocumentEdit, | 10 | PublishDiagnosticsParams, ReferenceParams, SignatureHelp, TextDocumentEdit, |
11 | TextDocumentPositionParams, TextEdit, WorkspaceEdit, WorkspaceSymbolParams | 11 | TextDocumentPositionParams, TextEdit, WorkspaceEdit, WorkspaceSymbolParams, |
12 | MessageType, ShowMessageParams, | ||
12 | }; | 13 | }; |
13 | 14 | ||
14 | pub enum AnalyzerStatus {} | 15 | pub enum AnalyzerStatus {} |