Unnamed repository; edit this file 'description' to name the repository.
Merge #10024
10024: fix: Fix reporting of build script errors r=matklad a=jonas-schievink r? `@matklad` (mostly to double-check that the redundant code I removed was, in fact, redundant) Fixes https://github.com/rust-analyzer/rust-analyzer/issues/9864 Fixes https://github.com/rust-analyzer/rust-analyzer/issues/10023 Co-authored-by: Jonas Schievink <[email protected]>
bors[bot] 2021-08-26
parent ce4670f · parent 276f6c6 · commit cbbb7f3
-rw-r--r--crates/project_model/src/build_scripts.rs6
-rw-r--r--crates/rust-analyzer/src/reload.rs32
2 files changed, 22 insertions, 16 deletions
diff --git a/crates/project_model/src/build_scripts.rs b/crates/project_model/src/build_scripts.rs
index fb8cc271c5..6b601c34a2 100644
--- a/crates/project_model/src/build_scripts.rs
+++ b/crates/project_model/src/build_scripts.rs
@@ -42,7 +42,7 @@ pub(crate) struct BuildScriptOutput {
}
impl WorkspaceBuildScripts {
- pub fn run(
+ pub(crate) fn run(
config: &CargoConfig,
workspace: &CargoWorkspace,
progress: &dyn Fn(String),
@@ -196,6 +196,10 @@ impl WorkspaceBuildScripts {
Ok(res)
}
+
+ pub fn error(&self) -> Option<&str> {
+ self.error.as_deref()
+ }
}
// FIXME: File a better way to know if it is a dylib.
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs
index 5c23caa685..efac6d6868 100644
--- a/crates/rust-analyzer/src/reload.rs
+++ b/crates/rust-analyzer/src/reload.rs
@@ -232,14 +232,6 @@ impl GlobalState {
let mut res = Vec::new();
for ws in workspaces.iter() {
res.push(ws.run_build_scripts(&config, &progress));
- let ws = match ws {
- ProjectWorkspace::Cargo { cargo, .. } => cargo,
- ProjectWorkspace::DetachedFiles { .. } | ProjectWorkspace::Json { .. } => {
- res.push(Ok(WorkspaceBuildScripts::default()));
- continue;
- }
- };
- res.push(WorkspaceBuildScripts::run(&config, ws, &progress))
}
sender.send(Task::FetchBuildData(BuildDataProgress::End((workspaces, res)))).unwrap();
});
@@ -453,19 +445,29 @@ impl GlobalState {
}
fn fetch_build_data_error(&self) -> Option<String> {
- let mut buf = String::new();
+ let mut buf = "rust-analyzer failed to run build scripts:\n".to_string();
+ let mut has_errors = false;
for ws in &self.fetch_build_data_queue.last_op_result().1 {
- if let Err(err) = ws {
- stdx::format_to!(buf, "rust-analyzer failed to run custom build: {:#}\n", err);
+ match ws {
+ Ok(data) => {
+ if let Some(err) = data.error() {
+ has_errors = true;
+ stdx::format_to!(buf, "{:#}\n", err);
+ }
+ }
+ Err(err) => {
+ has_errors = true;
+ stdx::format_to!(buf, "{:#}\n", err);
+ }
}
}
- if buf.is_empty() {
- return None;
+ if has_errors {
+ Some(buf)
+ } else {
+ None
}
-
- Some(buf)
}
fn reload_flycheck(&mut self) {