Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Propagate build errors using window/showMessage #657

Merged
merged 2 commits into from
Mar 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/actions/post_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ impl PostBuildHandler {
trace!("build - Error {} when running {:?}", cause, cmd);
self.notifier.notify_begin_diagnostics();
if !self.shown_cargo_error.swap(true, Ordering::SeqCst) {
let msg = format!("There was an error trying to build, RLS features will be limited: {}", cause);
self.notifier.notify_error_diagnostics(&msg);
// It's not a good idea to make a long message here, the output in
// VSCode is one single line, and it's important to capture the
// root cause.
self.notifier.notify_error_diagnostics(cause);
}
self.notifier.notify_end_diagnostics();
self.active_build_count.fetch_sub(1, Ordering::SeqCst);
Expand Down
14 changes: 7 additions & 7 deletions src/actions/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub enum ProgressUpdate {
pub trait DiagnosticsNotifier: Send {
fn notify_begin_diagnostics(&self);
fn notify_publish_diagnostics(&self, PublishDiagnosticsParams);
fn notify_error_diagnostics(&self, msg: String);
fn notify_end_diagnostics(&self);
fn notify_error_diagnostics(&self, msg: &str);
}

/// Generate a new progress params with a unique ID and the given title.
Expand Down Expand Up @@ -121,15 +121,15 @@ impl<O: Output> DiagnosticsNotifier for BuildDiagnosticsNotifier<O> {
fn notify_publish_diagnostics(&self, params: PublishDiagnosticsParams) {
self.out.notify(Notification::<PublishDiagnostics>::new(params));
}
fn notify_error_diagnostics(&self, message: String) {
self.out.notify(Notification::<ShowMessage>::new(ShowMessageParams {
typ: MessageType::Error,
message: message.to_owned(),
}));
}
fn notify_end_diagnostics(&self) {
let mut params = self.progress_params.clone();
params.done = Some(true);
self.out.notify(Notification::<Progress>::new(params));
}
fn notify_error_diagnostics(&self, msg: &str) {
self.out.notify(Notification::<ShowMessage>::new(ShowMessageParams {
typ: MessageType::Error,
message: msg.to_owned(),
}));
}
}
12 changes: 10 additions & 2 deletions src/build/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,17 @@ pub(super) fn cargo(internals: &Internals, package_arg: PackageArg, progress_sen
}
Ok(cwd) => BuildResult::Success(cwd, vec![], vec![], true),
Err(err) => {
// This message goes like this to the UI via showMessage. In VSCode
// this ends up on one single line, so it's important to keep it concise.
let stdout = String::from_utf8(out_clone.lock().unwrap().to_owned()).unwrap();
debug!("cargo failed\ncause: {}\nstdout: {}", err, stdout);
BuildResult::Err(err.to_string(), None)
let stdout_msg = if stdout.is_empty() {
"".to_string()
} else {
format!("({})", stdout)
};
let msg = format!("Cargo failed: {}{}", err, stdout_msg);
debug!("{}", msg);
BuildResult::Err(msg, None)
}
}
}
Expand Down