diff options
author | Aleksey Kladov <[email protected]> | 2021-04-06 16:08:05 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2021-04-06 16:08:05 +0100 |
commit | de3370278468e5135e4990fc14562e5ce523ef37 (patch) | |
tree | bd433d92a1a44b9b5bc7a6603b7862ed47c3937b /crates/project_model | |
parent | 9ec5e6e4fdbe893f38d10dbdc609284368efdb64 (diff) |
feat: show errors from `cargo metadata` and initial `cargo check` in the status bar
closes #3155
Diffstat (limited to 'crates/project_model')
-rw-r--r-- | crates/project_model/src/build_data.rs | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/crates/project_model/src/build_data.rs b/crates/project_model/src/build_data.rs index fdf4b2d55..0d4d39fef 100644 --- a/crates/project_model/src/build_data.rs +++ b/crates/project_model/src/build_data.rs | |||
@@ -13,7 +13,7 @@ use cargo_metadata::{BuildScript, Message}; | |||
13 | use itertools::Itertools; | 13 | use itertools::Itertools; |
14 | use paths::{AbsPath, AbsPathBuf}; | 14 | use paths::{AbsPath, AbsPathBuf}; |
15 | use rustc_hash::FxHashMap; | 15 | use rustc_hash::FxHashMap; |
16 | use stdx::JodChild; | 16 | use stdx::{format_to, JodChild}; |
17 | 17 | ||
18 | use crate::{cfg_flag::CfgFlag, CargoConfig}; | 18 | use crate::{cfg_flag::CfgFlag, CargoConfig}; |
19 | 19 | ||
@@ -35,6 +35,7 @@ pub(crate) struct PackageBuildData { | |||
35 | #[derive(Debug, Default, PartialEq, Eq, Clone)] | 35 | #[derive(Debug, Default, PartialEq, Eq, Clone)] |
36 | pub(crate) struct WorkspaceBuildData { | 36 | pub(crate) struct WorkspaceBuildData { |
37 | per_package: FxHashMap<String, PackageBuildData>, | 37 | per_package: FxHashMap<String, PackageBuildData>, |
38 | error: Option<String>, | ||
38 | } | 39 | } |
39 | 40 | ||
40 | #[derive(Debug, Default, PartialEq, Eq, Clone)] | 41 | #[derive(Debug, Default, PartialEq, Eq, Clone)] |
@@ -94,6 +95,19 @@ impl BuildDataResult { | |||
94 | pub(crate) fn get(&self, workspace_root: &AbsPath) -> Option<&WorkspaceBuildData> { | 95 | pub(crate) fn get(&self, workspace_root: &AbsPath) -> Option<&WorkspaceBuildData> { |
95 | self.per_workspace.get(workspace_root) | 96 | self.per_workspace.get(workspace_root) |
96 | } | 97 | } |
98 | pub fn error(&self) -> Option<String> { | ||
99 | let mut buf = String::new(); | ||
100 | for (_workspace_root, build_data) in &self.per_workspace { | ||
101 | if let Some(err) = &build_data.error { | ||
102 | format_to!(buf, "cargo check failed:\n{}", err); | ||
103 | } | ||
104 | } | ||
105 | if buf.is_empty() { | ||
106 | return None; | ||
107 | } | ||
108 | |||
109 | Some(buf) | ||
110 | } | ||
97 | } | 111 | } |
98 | 112 | ||
99 | impl BuildDataConfig { | 113 | impl BuildDataConfig { |
@@ -139,7 +153,7 @@ fn collect_from_workspace( | |||
139 | } | 153 | } |
140 | } | 154 | } |
141 | 155 | ||
142 | cmd.stdout(Stdio::piped()).stderr(Stdio::null()).stdin(Stdio::null()); | 156 | cmd.stdout(Stdio::piped()).stderr(Stdio::piped()).stdin(Stdio::null()); |
143 | 157 | ||
144 | let mut child = cmd.spawn().map(JodChild)?; | 158 | let mut child = cmd.spawn().map(JodChild)?; |
145 | let child_stdout = child.stdout.take().unwrap(); | 159 | let child_stdout = child.stdout.take().unwrap(); |
@@ -209,6 +223,15 @@ fn collect_from_workspace( | |||
209 | } | 223 | } |
210 | } | 224 | } |
211 | 225 | ||
226 | let output = child.into_inner().wait_with_output()?; | ||
227 | if !output.status.success() { | ||
228 | let mut stderr = String::from_utf8(output.stderr).unwrap_or_default(); | ||
229 | if stderr.is_empty() { | ||
230 | stderr = "cargo check failed".to_string(); | ||
231 | } | ||
232 | res.error = Some(stderr) | ||
233 | } | ||
234 | |||
212 | Ok(res) | 235 | Ok(res) |
213 | } | 236 | } |
214 | 237 | ||