mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 14:13:58 +00:00
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.
This commit is contained in:
parent
ab288a32f9
commit
9063dabcca
3 changed files with 27 additions and 20 deletions
|
@ -43,7 +43,7 @@ fn main_inner() -> Result<()> {
|
|||
.and_then(|v| InitializationOptions::deserialize(v).ok())
|
||||
.and_then(|it| it.publish_decorations)
|
||||
== Some(true);
|
||||
ra_lsp_server::main_loop(false, root, supports_decorations, r, s)
|
||||
ra_lsp_server::main_loop(root, supports_decorations, r, s)
|
||||
})?;
|
||||
log::info!("shutting down IO...");
|
||||
threads.join()?;
|
||||
|
|
|
@ -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<RawMessage>,
|
||||
|
@ -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::ShowMessage>(&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<RawMessage>,
|
||||
|
@ -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<RawMessage>) {
|
||||
if !intrnal_mode {
|
||||
return;
|
||||
}
|
||||
let not = RawNotification::new::<req::InternalFeedback>(&msg.to_string());
|
||||
fn feedback<M: Into<String>>(typ: req::MessageType, msg: M, sender: &Sender<RawMessage>) {
|
||||
let not = RawNotification::new::<req::ShowMessage>(&req::ShowMessageParams {
|
||||
typ,
|
||||
message: msg.into(),
|
||||
});
|
||||
|
||||
sender.send(not.into()).unwrap();
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ use lsp_types::{
|
|||
notification::DidOpenTextDocument,
|
||||
request::{Request, Shutdown},
|
||||
DidOpenTextDocumentParams, TextDocumentIdentifier, TextDocumentItem, Url,
|
||||
notification::{Notification, ShowMessage},
|
||||
};
|
||||
use serde::Serialize;
|
||||
use serde_json::{to_string_pretty, Value};
|
||||
|
@ -56,7 +57,7 @@ impl Server {
|
|||
"test server",
|
||||
128,
|
||||
move |mut msg_receiver, mut msg_sender| {
|
||||
main_loop(true, path, true, &mut msg_receiver, &mut msg_sender).unwrap()
|
||||
main_loop(path, true, &mut msg_receiver, &mut msg_sender).unwrap()
|
||||
},
|
||||
);
|
||||
let res = Server {
|
||||
|
@ -138,8 +139,9 @@ impl Server {
|
|||
}
|
||||
pub fn wait_for_feedback_n(&self, feedback: &str, n: usize) {
|
||||
let f = |msg: &RawMessage| match msg {
|
||||
RawMessage::Notification(n) if n.method == "internalFeedback" => {
|
||||
return n.clone().cast::<req::InternalFeedback>().unwrap() == feedback;
|
||||
RawMessage::Notification(n) if n.method == ShowMessage::METHOD => {
|
||||
let message = n.clone().cast::<req::ShowMessage>().unwrap();
|
||||
message.message == feedback
|
||||
}
|
||||
_ => false,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue