From 095df7bc39988453857e0fef5b773b405379b629 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 25 Aug 2021 17:56:24 +0200 Subject: [PATCH 1/3] Don't fetch build script output twice --- crates/rust-analyzer/src/reload.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs index 5c23caa685..cc32b0e2fe 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(); }); From 0ff2c81bb94417cd0e0b91d97443b59893e539ae Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 25 Aug 2021 17:56:39 +0200 Subject: [PATCH 2/3] Fix reporting of build script errors --- crates/project_model/src/build_scripts.rs | 4 ++++ crates/rust-analyzer/src/reload.rs | 24 ++++++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/crates/project_model/src/build_scripts.rs b/crates/project_model/src/build_scripts.rs index fb8cc271c5..7ed7de04fb 100644 --- a/crates/project_model/src/build_scripts.rs +++ b/crates/project_model/src/build_scripts.rs @@ -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 cc32b0e2fe..efac6d6868 100644 --- a/crates/rust-analyzer/src/reload.rs +++ b/crates/rust-analyzer/src/reload.rs @@ -445,19 +445,29 @@ impl GlobalState { } fn fetch_build_data_error(&self) -> Option { - 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) { From 276f6c6ba45e92c1eef920c69aebe9ed6169aaec Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 25 Aug 2021 18:02:27 +0200 Subject: [PATCH 3/3] Reduce visibility of `WorkspaceBuildScripts::run` --- crates/project_model/src/build_scripts.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/project_model/src/build_scripts.rs b/crates/project_model/src/build_scripts.rs index 7ed7de04fb..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),