From 9063dabcca0aaaa6d8bb3364cee21fd68023a059 Mon Sep 17 00:00:00 2001 From: Ville Penttinen Date: Tue, 5 Mar 2019 21:59:01 +0200 Subject: Send an actual ShowMessage instead of InternalFeedback in feedback() This now allows us to send a notification that can be shown in the UI when the workspace has been loaded. Additionally this removes the need for internal_mode flag. --- crates/ra_lsp_server/src/main_loop.rs | 37 ++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'crates/ra_lsp_server/src/main_loop.rs') diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index 0f8ef10b9..145f7bf65 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs @@ -46,7 +46,6 @@ enum Task { const THREADPOOL_SIZE: usize = 8; pub fn main_loop( - internal_mode: bool, ws_root: PathBuf, supports_decorations: bool, msg_receiver: &Receiver, @@ -63,11 +62,12 @@ 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(); + + feedback( + req::MessageType::Error, + format!("rust-analyzer failed to load workspace: {}", e), + msg_sender, + ); Vec::new() } } @@ -80,7 +80,6 @@ pub fn main_loop( let mut pending_requests = FxHashSet::default(); let mut subs = Subscriptions::new(); let main_res = main_loop_inner( - internal_mode, supports_decorations, &pool, msg_sender, @@ -148,7 +147,6 @@ impl fmt::Debug for Event { } fn main_loop_inner( - internal_mode: bool, supports_decorations: bool, pool: &ThreadPool, msg_sender: &Sender, @@ -163,6 +161,7 @@ fn main_loop_inner( // time to always have a thread ready to react to input. let mut in_flight_libraries = 0; let mut pending_libraries = Vec::new(); + let mut send_workspace_notification = true; let (libdata_sender, libdata_receiver) = unbounded(); loop { @@ -190,7 +189,6 @@ fn main_loop_inner( state_changed = true; } Event::Lib(lib) => { - feedback(internal_mode, "library loaded", msg_sender); state.add_lib(lib); in_flight_libraries -= 1; } @@ -244,8 +242,14 @@ fn main_loop_inner( }); } - if state.roots_to_scan == 0 && pending_libraries.is_empty() && in_flight_libraries == 0 { - feedback(internal_mode, "workspace loaded", msg_sender); + if send_workspace_notification + && state.roots_to_scan == 0 + && pending_libraries.is_empty() + && in_flight_libraries == 0 + { + feedback(req::MessageType::Info, "workspace loaded", msg_sender); + // Only send the notification first time + send_workspace_notification = false; } if state_changed { @@ -501,11 +505,12 @@ fn update_file_notifications_on_threadpool( }); } -fn feedback(intrnal_mode: bool, msg: &str, sender: &Sender) { - if !intrnal_mode { - return; - } - let not = RawNotification::new::(&msg.to_string()); +fn feedback>(typ: req::MessageType, msg: M, sender: &Sender) { + let not = RawNotification::new::(&req::ShowMessageParams { + typ, + message: msg.into(), + }); + sender.send(not.into()).unwrap(); } -- cgit v1.2.3