mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 21:35:20 +00:00
Merge #946
946: when loading workspace, say how many packages were loaded r=matklad a=matklad Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
a41d8e140c
3 changed files with 21 additions and 22 deletions
|
@ -248,8 +248,10 @@ fn main_loop_inner(
|
||||||
&& pending_libraries.is_empty()
|
&& pending_libraries.is_empty()
|
||||||
&& in_flight_libraries == 0
|
&& in_flight_libraries == 0
|
||||||
{
|
{
|
||||||
|
let n_packages: usize = state.workspaces.iter().map(|it| it.count()).sum();
|
||||||
if options.show_workspace_loaded {
|
if options.show_workspace_loaded {
|
||||||
show_message(req::MessageType::Info, "workspace loaded", msg_sender);
|
let msg = format!("workspace loaded, {} rust packages", n_packages);
|
||||||
|
show_message(req::MessageType::Info, msg, msg_sender);
|
||||||
}
|
}
|
||||||
// Only send the notification first time
|
// Only send the notification first time
|
||||||
send_workspace_notification = false;
|
send_workspace_notification = false;
|
||||||
|
@ -508,12 +510,10 @@ fn update_file_notifications_on_threadpool(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn show_message<M: Into<String>>(typ: req::MessageType, msg: M, sender: &Sender<RawMessage>) {
|
fn show_message(typ: req::MessageType, message: impl Into<String>, sender: &Sender<RawMessage>) {
|
||||||
let not = RawNotification::new::<req::ShowMessage>(&req::ShowMessageParams {
|
let message = message.into();
|
||||||
typ,
|
let params = req::ShowMessageParams { typ, message };
|
||||||
message: msg.into(),
|
let not = RawNotification::new::<req::ShowMessage>(¶ms);
|
||||||
});
|
|
||||||
|
|
||||||
sender.send(not.into()).unwrap();
|
sender.send(not.into()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ version = "0.0.0"
|
||||||
use std::collections::Spam;
|
use std::collections::Spam;
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
server.wait_for_message("workspace loaded");
|
server.wait_until_workspace_is_loaded();
|
||||||
eprintln!("loading took {:?}", project_start.elapsed());
|
eprintln!("loading took {:?}", project_start.elapsed());
|
||||||
let completion_start = Instant::now();
|
let completion_start = Instant::now();
|
||||||
let res = server.send_request::<Completion>(CompletionParams {
|
let res = server.send_request::<Completion>(CompletionParams {
|
||||||
|
@ -54,7 +54,7 @@ fn foo() {
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
server.wait_for_message("workspace loaded");
|
server.wait_until_workspace_is_loaded();
|
||||||
server.request::<Runnables>(
|
server.request::<Runnables>(
|
||||||
RunnablesParams { text_document: server.doc_id("lib.rs"), position: None },
|
RunnablesParams { text_document: server.doc_id("lib.rs"), position: None },
|
||||||
json!([
|
json!([
|
||||||
|
@ -108,7 +108,7 @@ pub fn foo() {}
|
||||||
fn test_eggs() {}
|
fn test_eggs() {}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
server.wait_for_message("workspace loaded");
|
server.wait_until_workspace_is_loaded();
|
||||||
server.request::<Runnables>(
|
server.request::<Runnables>(
|
||||||
RunnablesParams {
|
RunnablesParams {
|
||||||
text_document: server.doc_id("tests/spam.rs"),
|
text_document: server.doc_id("tests/spam.rs"),
|
||||||
|
@ -168,7 +168,7 @@ fn main() {
|
||||||
pub use std::collections::HashMap;
|
pub use std::collections::HashMap;
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
server.wait_for_message("workspace loaded");
|
server.wait_until_workspace_is_loaded();
|
||||||
|
|
||||||
server.request::<Formatting>(
|
server.request::<Formatting>(
|
||||||
DocumentFormattingParams {
|
DocumentFormattingParams {
|
||||||
|
@ -217,7 +217,7 @@ mod bar;
|
||||||
fn main() {}
|
fn main() {}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
server.wait_for_message("workspace loaded");
|
server.wait_until_workspace_is_loaded();
|
||||||
let empty_context = || CodeActionContext { diagnostics: Vec::new(), only: None };
|
let empty_context = || CodeActionContext { diagnostics: Vec::new(), only: None };
|
||||||
server.request::<CodeActionRequest>(
|
server.request::<CodeActionRequest>(
|
||||||
CodeActionParams {
|
CodeActionParams {
|
||||||
|
@ -279,7 +279,7 @@ fn main() {}
|
||||||
PATH = tmp_dir.path().display()
|
PATH = tmp_dir.path().display()
|
||||||
);
|
);
|
||||||
let server = project_with_tmpdir(tmp_dir, &code);
|
let server = project_with_tmpdir(tmp_dir, &code);
|
||||||
server.wait_for_message("workspace loaded");
|
server.wait_until_workspace_is_loaded();
|
||||||
let empty_context = || CodeActionContext { diagnostics: Vec::new(), only: None };
|
let empty_context = || CodeActionContext { diagnostics: Vec::new(), only: None };
|
||||||
server.request::<CodeActionRequest>(
|
server.request::<CodeActionRequest>(
|
||||||
CodeActionParams {
|
CodeActionParams {
|
||||||
|
|
|
@ -145,26 +145,25 @@ impl Server {
|
||||||
}
|
}
|
||||||
panic!("no response");
|
panic!("no response");
|
||||||
}
|
}
|
||||||
pub fn wait_for_message(&self, message: &str) {
|
pub fn wait_until_workspace_is_loaded(&self) {
|
||||||
self.wait_for_message_n(message, 1)
|
self.wait_for_message_cond(1, &|msg: &RawMessage| match msg {
|
||||||
}
|
|
||||||
pub fn wait_for_message_n(&self, message: &str, n: usize) {
|
|
||||||
let f = |msg: &RawMessage| match msg {
|
|
||||||
RawMessage::Notification(n) if n.method == ShowMessage::METHOD => {
|
RawMessage::Notification(n) if n.method == ShowMessage::METHOD => {
|
||||||
let msg = n.clone().cast::<req::ShowMessage>().unwrap();
|
let msg = n.clone().cast::<req::ShowMessage>().unwrap();
|
||||||
msg.message == message
|
msg.message.starts_with("workspace loaded")
|
||||||
}
|
}
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
})
|
||||||
|
}
|
||||||
|
fn wait_for_message_cond(&self, n: usize, cond: &dyn Fn(&RawMessage) -> bool) {
|
||||||
let mut total = 0;
|
let mut total = 0;
|
||||||
for msg in self.messages.borrow().iter() {
|
for msg in self.messages.borrow().iter() {
|
||||||
if f(msg) {
|
if cond(msg) {
|
||||||
total += 1
|
total += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while total < n {
|
while total < n {
|
||||||
let msg = self.recv().expect("no response");
|
let msg = self.recv().expect("no response");
|
||||||
if f(&msg) {
|
if cond(&msg) {
|
||||||
total += 1;
|
total += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue