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

Commit abd4727

Browse files
committed
Improved showMessage on build errors
1 parent 8e781f7 commit abd4727

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

src/actions/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,9 @@ impl InitActionContext {
226226
shown_cargo_error: self.shown_cargo_error.clone(),
227227
active_build_count: self.active_build_count.clone(),
228228
use_black_list: config.use_crate_blacklist,
229-
notifier: Box::new(BuildDiagnosticsNotifier::new(out.clone())),
229+
notifier: Box::new(BuildDiagnosticsNotifier::new(
230+
out.clone(),
231+
)),
230232
blocked_threads: vec![],
231233
}
232234
};

src/actions/post_build.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,11 @@ impl PostBuildHandler {
8686
trace!("build - Error {} when running {:?}", cause, cmd);
8787
self.notifier.notify_begin_diagnostics();
8888
if !self.shown_cargo_error.swap(true, Ordering::SeqCst) {
89-
let msg = format!("There was an error trying to build, RLS features will be limited: {}", cause);
90-
self.notifier.notify_error_diagnostics(&msg);
89+
// It's not a good idea to make a long message here, the output in
90+
// VSCode is one single line, and it's important to capture the
91+
// root cause.
92+
// let msg = format!("There was an error trying to build, RLS features will be limited: {}", cause);
93+
self.notifier.notify_build_error_diagnostics(cause);
9194
}
9295
self.notifier.notify_end_diagnostics();
9396
self.active_build_count.fetch_sub(1, Ordering::SeqCst);

src/actions/progress.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ pub enum ProgressUpdate {
3434
pub trait DiagnosticsNotifier: Send {
3535
fn notify_begin_diagnostics(&self);
3636
fn notify_publish_diagnostics(&self, PublishDiagnosticsParams);
37+
fn notify_build_error_diagnostics(&self, msg: String);
3738
fn notify_end_diagnostics(&self);
38-
fn notify_error_diagnostics(&self, msg: &str);
3939
}
4040

4141
/// Generate a new progress params with a unique ID and the given title.
@@ -121,15 +121,15 @@ impl<O: Output> DiagnosticsNotifier for BuildDiagnosticsNotifier<O> {
121121
fn notify_publish_diagnostics(&self, params: PublishDiagnosticsParams) {
122122
self.out.notify(Notification::<PublishDiagnostics>::new(params));
123123
}
124+
fn notify_build_error_diagnostics(&self, message: String) {
125+
self.out.notify(Notification::<ShowMessage>::new(ShowMessageParams {
126+
typ: MessageType::Error,
127+
message: message.to_owned(),
128+
}));
129+
}
124130
fn notify_end_diagnostics(&self) {
125131
let mut params = self.progress_params.clone();
126132
params.done = Some(true);
127133
self.out.notify(Notification::<Progress>::new(params));
128134
}
129-
fn notify_error_diagnostics(&self, msg: &str) {
130-
self.out.notify(Notification::<ShowMessage>::new(ShowMessageParams {
131-
typ: MessageType::Error,
132-
message: msg.to_owned(),
133-
}));
134-
}
135135
}

src/build/cargo.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,14 @@ pub(super) fn cargo(internals: &Internals, package_arg: PackageArg, progress_sen
8686
Ok(cwd) => BuildResult::Success(cwd, vec![], vec![], true),
8787
Err(err) => {
8888
let stdout = String::from_utf8(out_clone.lock().unwrap().to_owned()).unwrap();
89-
debug!("cargo failed\ncause: {}\nstdout: {}", err, stdout);
90-
BuildResult::Err(err.to_string(), None)
89+
let stdout_msg = if stdout.is_empty() {
90+
"".to_string()
91+
} else {
92+
format!("({})", stdout)
93+
};
94+
let msg = format!("Cargo failed: {}{}", err, stdout_msg);
95+
info!("{}", msg);
96+
BuildResult::Err(msg, None)
9197
}
9298
}
9399
}

0 commit comments

Comments
 (0)