diff --git a/crates/project_model/src/build_scripts.rs b/crates/project_model/src/build_scripts.rs index fb8cc271c51..6b601c34a24 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 5c23caa6853..efac6d68687 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 { - 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) {