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

Commit b113fcd

Browse files
authored
Merge pull request #657 from algesten/build-err
Propagate build errors using window/showMessage
2 parents af9e80f + 635d220 commit b113fcd

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

src/actions/post_build.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,10 @@ 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+
self.notifier.notify_error_diagnostics(cause);
9193
}
9294
self.notifier.notify_end_diagnostics();
9395
self.active_build_count.fetch_sub(1, Ordering::SeqCst);

src/actions/progress.rs

Lines changed: 7 additions & 7 deletions
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_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_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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,17 @@ pub(super) fn cargo(internals: &Internals, package_arg: PackageArg, progress_sen
8585
}
8686
Ok(cwd) => BuildResult::Success(cwd, vec![], vec![], true),
8787
Err(err) => {
88+
// This message goes like this to the UI via showMessage. In VSCode
89+
// this ends up on one single line, so it's important to keep it concise.
8890
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)
91+
let stdout_msg = if stdout.is_empty() {
92+
"".to_string()
93+
} else {
94+
format!("({})", stdout)
95+
};
96+
let msg = format!("Cargo failed: {}{}", err, stdout_msg);
97+
debug!("{}", msg);
98+
BuildResult::Err(msg, None)
9199
}
92100
}
93101
}

0 commit comments

Comments
 (0)