diff options
author | Ville Penttinen <[email protected]> | 2019-03-05 19:59:01 +0000 |
---|---|---|
committer | Ville Penttinen <[email protected]> | 2019-03-05 19:59:01 +0000 |
commit | 9063dabcca0aaaa6d8bb3364cee21fd68023a059 (patch) | |
tree | ea85c8abd5ba57f0120556987a1c8cc5c6eae19d /crates | |
parent | ab288a32f9a95e3ca5e9e42f9c6f59bb3849f26e (diff) |
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.
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_lsp_server/src/main.rs | 2 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop.rs | 37 | ||||
-rw-r--r-- | crates/ra_lsp_server/tests/heavy_tests/support.rs | 8 |
3 files changed, 27 insertions, 20 deletions
diff --git a/crates/ra_lsp_server/src/main.rs b/crates/ra_lsp_server/src/main.rs index 03f83c7be..9dc2e3f87 100644 --- a/crates/ra_lsp_server/src/main.rs +++ b/crates/ra_lsp_server/src/main.rs | |||
@@ -43,7 +43,7 @@ fn main_inner() -> Result<()> { | |||
43 | .and_then(|v| InitializationOptions::deserialize(v).ok()) | 43 | .and_then(|v| InitializationOptions::deserialize(v).ok()) |
44 | .and_then(|it| it.publish_decorations) | 44 | .and_then(|it| it.publish_decorations) |
45 | == Some(true); | 45 | == Some(true); |
46 | ra_lsp_server::main_loop(false, root, supports_decorations, r, s) | 46 | ra_lsp_server::main_loop(root, supports_decorations, r, s) |
47 | })?; | 47 | })?; |
48 | log::info!("shutting down IO..."); | 48 | log::info!("shutting down IO..."); |
49 | threads.join()?; | 49 | threads.join()?; |
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 { | |||
46 | const THREADPOOL_SIZE: usize = 8; | 46 | const THREADPOOL_SIZE: usize = 8; |
47 | 47 | ||
48 | pub fn main_loop( | 48 | pub fn main_loop( |
49 | internal_mode: bool, | ||
50 | ws_root: PathBuf, | 49 | ws_root: PathBuf, |
51 | supports_decorations: bool, | 50 | supports_decorations: bool, |
52 | msg_receiver: &Receiver<RawMessage>, | 51 | msg_receiver: &Receiver<RawMessage>, |
@@ -63,11 +62,12 @@ pub fn main_loop( | |||
63 | Ok(ws) => vec![ws], | 62 | Ok(ws) => vec![ws], |
64 | Err(e) => { | 63 | Err(e) => { |
65 | log::error!("loading workspace failed: {}", e); | 64 | log::error!("loading workspace failed: {}", e); |
66 | let msg = RawNotification::new::<req::ShowMessage>(&req::ShowMessageParams { | 65 | |
67 | typ: req::MessageType::Error, | 66 | feedback( |
68 | message: format!("rust-analyzer failed to load workspace: {}", e), | 67 | req::MessageType::Error, |
69 | }); | 68 | format!("rust-analyzer failed to load workspace: {}", e), |
70 | msg_sender.send(msg.into()).unwrap(); | 69 | msg_sender, |
70 | ); | ||
71 | Vec::new() | 71 | Vec::new() |
72 | } | 72 | } |
73 | } | 73 | } |
@@ -80,7 +80,6 @@ pub fn main_loop( | |||
80 | let mut pending_requests = FxHashSet::default(); | 80 | let mut pending_requests = FxHashSet::default(); |
81 | let mut subs = Subscriptions::new(); | 81 | let mut subs = Subscriptions::new(); |
82 | let main_res = main_loop_inner( | 82 | let main_res = main_loop_inner( |
83 | internal_mode, | ||
84 | supports_decorations, | 83 | supports_decorations, |
85 | &pool, | 84 | &pool, |
86 | msg_sender, | 85 | msg_sender, |
@@ -148,7 +147,6 @@ impl fmt::Debug for Event { | |||
148 | } | 147 | } |
149 | 148 | ||
150 | fn main_loop_inner( | 149 | fn main_loop_inner( |
151 | internal_mode: bool, | ||
152 | supports_decorations: bool, | 150 | supports_decorations: bool, |
153 | pool: &ThreadPool, | 151 | pool: &ThreadPool, |
154 | msg_sender: &Sender<RawMessage>, | 152 | msg_sender: &Sender<RawMessage>, |
@@ -163,6 +161,7 @@ fn main_loop_inner( | |||
163 | // time to always have a thread ready to react to input. | 161 | // time to always have a thread ready to react to input. |
164 | let mut in_flight_libraries = 0; | 162 | let mut in_flight_libraries = 0; |
165 | let mut pending_libraries = Vec::new(); | 163 | let mut pending_libraries = Vec::new(); |
164 | let mut send_workspace_notification = true; | ||
166 | 165 | ||
167 | let (libdata_sender, libdata_receiver) = unbounded(); | 166 | let (libdata_sender, libdata_receiver) = unbounded(); |
168 | loop { | 167 | loop { |
@@ -190,7 +189,6 @@ fn main_loop_inner( | |||
190 | state_changed = true; | 189 | state_changed = true; |
191 | } | 190 | } |
192 | Event::Lib(lib) => { | 191 | Event::Lib(lib) => { |
193 | feedback(internal_mode, "library loaded", msg_sender); | ||
194 | state.add_lib(lib); | 192 | state.add_lib(lib); |
195 | in_flight_libraries -= 1; | 193 | in_flight_libraries -= 1; |
196 | } | 194 | } |
@@ -244,8 +242,14 @@ fn main_loop_inner( | |||
244 | }); | 242 | }); |
245 | } | 243 | } |
246 | 244 | ||
247 | if state.roots_to_scan == 0 && pending_libraries.is_empty() && in_flight_libraries == 0 { | 245 | if send_workspace_notification |
248 | feedback(internal_mode, "workspace loaded", msg_sender); | 246 | && state.roots_to_scan == 0 |
247 | && pending_libraries.is_empty() | ||
248 | && in_flight_libraries == 0 | ||
249 | { | ||
250 | feedback(req::MessageType::Info, "workspace loaded", msg_sender); | ||
251 | // Only send the notification first time | ||
252 | send_workspace_notification = false; | ||
249 | } | 253 | } |
250 | 254 | ||
251 | if state_changed { | 255 | if state_changed { |
@@ -501,11 +505,12 @@ fn update_file_notifications_on_threadpool( | |||
501 | }); | 505 | }); |
502 | } | 506 | } |
503 | 507 | ||
504 | fn feedback(intrnal_mode: bool, msg: &str, sender: &Sender<RawMessage>) { | 508 | fn feedback<M: Into<String>>(typ: req::MessageType, msg: M, sender: &Sender<RawMessage>) { |
505 | if !intrnal_mode { | 509 | let not = RawNotification::new::<req::ShowMessage>(&req::ShowMessageParams { |
506 | return; | 510 | typ, |
507 | } | 511 | message: msg.into(), |
508 | let not = RawNotification::new::<req::InternalFeedback>(&msg.to_string()); | 512 | }); |
513 | |||
509 | sender.send(not.into()).unwrap(); | 514 | sender.send(not.into()).unwrap(); |
510 | } | 515 | } |
511 | 516 | ||
diff --git a/crates/ra_lsp_server/tests/heavy_tests/support.rs b/crates/ra_lsp_server/tests/heavy_tests/support.rs index f4e7eaf75..3a7c50309 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/support.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/support.rs | |||
@@ -13,6 +13,7 @@ use lsp_types::{ | |||
13 | notification::DidOpenTextDocument, | 13 | notification::DidOpenTextDocument, |
14 | request::{Request, Shutdown}, | 14 | request::{Request, Shutdown}, |
15 | DidOpenTextDocumentParams, TextDocumentIdentifier, TextDocumentItem, Url, | 15 | DidOpenTextDocumentParams, TextDocumentIdentifier, TextDocumentItem, Url, |
16 | notification::{Notification, ShowMessage}, | ||
16 | }; | 17 | }; |
17 | use serde::Serialize; | 18 | use serde::Serialize; |
18 | use serde_json::{to_string_pretty, Value}; | 19 | use serde_json::{to_string_pretty, Value}; |
@@ -56,7 +57,7 @@ impl Server { | |||
56 | "test server", | 57 | "test server", |
57 | 128, | 58 | 128, |
58 | move |mut msg_receiver, mut msg_sender| { | 59 | move |mut msg_receiver, mut msg_sender| { |
59 | main_loop(true, path, true, &mut msg_receiver, &mut msg_sender).unwrap() | 60 | main_loop(path, true, &mut msg_receiver, &mut msg_sender).unwrap() |
60 | }, | 61 | }, |
61 | ); | 62 | ); |
62 | let res = Server { | 63 | let res = Server { |
@@ -138,8 +139,9 @@ impl Server { | |||
138 | } | 139 | } |
139 | pub fn wait_for_feedback_n(&self, feedback: &str, n: usize) { | 140 | pub fn wait_for_feedback_n(&self, feedback: &str, n: usize) { |
140 | let f = |msg: &RawMessage| match msg { | 141 | let f = |msg: &RawMessage| match msg { |
141 | RawMessage::Notification(n) if n.method == "internalFeedback" => { | 142 | RawMessage::Notification(n) if n.method == ShowMessage::METHOD => { |
142 | return n.clone().cast::<req::InternalFeedback>().unwrap() == feedback; | 143 | let message = n.clone().cast::<req::ShowMessage>().unwrap(); |
144 | message.message == feedback | ||
143 | } | 145 | } |
144 | _ => false, | 146 | _ => false, |
145 | }; | 147 | }; |