Skip to content

Commit cbbb7f3

Browse files
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 #9864 Fixes #10023 Co-authored-by: Jonas Schievink <[email protected]>
2 parents ce4670f + 276f6c6 commit cbbb7f3

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

crates/project_model/src/build_scripts.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub(crate) struct BuildScriptOutput {
4242
}
4343

4444
impl WorkspaceBuildScripts {
45-
pub fn run(
45+
pub(crate) fn run(
4646
config: &CargoConfig,
4747
workspace: &CargoWorkspace,
4848
progress: &dyn Fn(String),
@@ -196,6 +196,10 @@ impl WorkspaceBuildScripts {
196196

197197
Ok(res)
198198
}
199+
200+
pub fn error(&self) -> Option<&str> {
201+
self.error.as_deref()
202+
}
199203
}
200204

201205
// FIXME: File a better way to know if it is a dylib.

crates/rust-analyzer/src/reload.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,6 @@ impl GlobalState {
232232
let mut res = Vec::new();
233233
for ws in workspaces.iter() {
234234
res.push(ws.run_build_scripts(&config, &progress));
235-
let ws = match ws {
236-
ProjectWorkspace::Cargo { cargo, .. } => cargo,
237-
ProjectWorkspace::DetachedFiles { .. } | ProjectWorkspace::Json { .. } => {
238-
res.push(Ok(WorkspaceBuildScripts::default()));
239-
continue;
240-
}
241-
};
242-
res.push(WorkspaceBuildScripts::run(&config, ws, &progress))
243235
}
244236
sender.send(Task::FetchBuildData(BuildDataProgress::End((workspaces, res)))).unwrap();
245237
});
@@ -453,19 +445,29 @@ impl GlobalState {
453445
}
454446

455447
fn fetch_build_data_error(&self) -> Option<String> {
456-
let mut buf = String::new();
448+
let mut buf = "rust-analyzer failed to run build scripts:\n".to_string();
449+
let mut has_errors = false;
457450

458451
for ws in &self.fetch_build_data_queue.last_op_result().1 {
459-
if let Err(err) = ws {
460-
stdx::format_to!(buf, "rust-analyzer failed to run custom build: {:#}\n", err);
452+
match ws {
453+
Ok(data) => {
454+
if let Some(err) = data.error() {
455+
has_errors = true;
456+
stdx::format_to!(buf, "{:#}\n", err);
457+
}
458+
}
459+
Err(err) => {
460+
has_errors = true;
461+
stdx::format_to!(buf, "{:#}\n", err);
462+
}
461463
}
462464
}
463465

464-
if buf.is_empty() {
465-
return None;
466+
if has_errors {
467+
Some(buf)
468+
} else {
469+
None
466470
}
467-
468-
Some(buf)
469471
}
470472

471473
fn reload_flycheck(&mut self) {

0 commit comments

Comments
 (0)