From 73b892aaa3f889e987b6115d76a6e41df6c478e1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 5 Mar 2019 16:24:59 +0300 Subject: show message in client's UI if workspace fails to load --- crates/gen_lsp_server/src/msg.rs | 18 ++++++++++++++++++ crates/ra_lsp_server/src/main_loop.rs | 19 ++++++++++++------- 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 { Response(RawResponse), } +impl From for RawMessage { + fn from(raw: RawRequest) -> RawMessage { + RawMessage::Request(raw) + } +} + +impl From for RawMessage { + fn from(raw: RawNotification) -> RawMessage { + RawMessage::Notification(raw) + } +} + +impl From for RawMessage { + fn from(raw: RawResponse) -> RawMessage { + RawMessage::Response(raw) + } +} + #[derive(Debug, Serialize, Deserialize, Clone)] pub struct RawRequest { 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( Ok(ws) => vec![ws], Err(e) => { log::error!("loading workspace failed: {}", e); + let msg = RawNotification::new::(&req::ShowMessageParams { + typ: req::MessageType::Error, + message: format!("rust-analyzer failed to load workspace: {}", e), + }); + msg_sender.send(msg.into()).unwrap(); Vec::new() } } @@ -199,7 +204,7 @@ fn main_loop_inner( Ok((id, ())) => { state.collect_garbage(); let resp = RawResponse::ok::(id, &()); - msg_sender.send(RawMessage::Response(resp)).unwrap() + msg_sender.send(resp.into()).unwrap() } Err(req) => { match on_request(state, pending_requests, pool, &task_sender, req)? { @@ -211,7 +216,7 @@ fn main_loop_inner( ErrorCode::MethodNotFound as i32, "unknown request".to_string(), ); - msg_sender.send(RawMessage::Response(resp)).unwrap() + msg_sender.send(resp.into()).unwrap() } } } @@ -260,11 +265,11 @@ fn on_task(task: Task, msg_sender: &Sender, pending_requests: &mut F match task { Task::Respond(response) => { if pending_requests.remove(&response.id) { - msg_sender.send(RawMessage::Response(response)).unwrap(); + msg_sender.send(response.into()).unwrap(); } } Task::Notify(n) => { - msg_sender.send(RawMessage::Notification(n)).unwrap(); + msg_sender.send(n.into()).unwrap(); } } } @@ -336,7 +341,7 @@ fn on_notification( ErrorCode::RequestCanceled as i32, "canceled by client".to_string(), ); - msg_sender.send(RawMessage::Response(response)).unwrap() + msg_sender.send(response.into()).unwrap() } return Ok(()); } @@ -375,7 +380,7 @@ fn on_notification( } let params = req::PublishDiagnosticsParams { uri, diagnostics: Vec::new() }; let not = RawNotification::new::(¶ms); - msg_sender.send(RawMessage::Notification(not)).unwrap(); + msg_sender.send(not.into()).unwrap(); return Ok(()); } Err(not) => not, @@ -501,7 +506,7 @@ fn feedback(intrnal_mode: bool, msg: &str, sender: &Sender) { return; } let not = RawNotification::new::(&msg.to_string()); - sender.send(RawMessage::Notification(not)).unwrap(); + sender.send(not.into()).unwrap(); } 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::{ CompletionParams, CompletionResponse, DocumentOnTypeFormattingParams, DocumentSymbolParams, DocumentSymbolResponse, ExecuteCommandParams, Hover, InitializeResult, PublishDiagnosticsParams, ReferenceParams, SignatureHelp, TextDocumentEdit, - TextDocumentPositionParams, TextEdit, WorkspaceEdit, WorkspaceSymbolParams + TextDocumentPositionParams, TextEdit, WorkspaceEdit, WorkspaceSymbolParams, + MessageType, ShowMessageParams, }; pub enum AnalyzerStatus {} -- cgit v1.2.3