diff options
author | Aleksey Kladov <[email protected]> | 2021-04-05 20:30:19 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2021-04-06 10:33:19 +0100 |
commit | aaa8c208b12e3ddb1b4a7fd3d843182ae12cdae5 (patch) | |
tree | a5833c960096a22e38beab5dda78cd4ddd3f736b /crates/rust-analyzer/src/reload.rs | |
parent | 047b5313013383fc4fafaef6d6d8d6a64549e3cb (diff) |
internal: do not drop errors from cargo metadata/check
Work towards #3155
Diffstat (limited to 'crates/rust-analyzer/src/reload.rs')
-rw-r--r-- | crates/rust-analyzer/src/reload.rs | 76 |
1 files changed, 36 insertions, 40 deletions
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs index d12f891bb..cdd6eae69 100644 --- a/crates/rust-analyzer/src/reload.rs +++ b/crates/rust-analyzer/src/reload.rs | |||
@@ -139,8 +139,11 @@ impl GlobalState { | |||
139 | sender.send(Task::FetchBuildData(BuildDataProgress::End(res))).unwrap(); | 139 | sender.send(Task::FetchBuildData(BuildDataProgress::End(res))).unwrap(); |
140 | }); | 140 | }); |
141 | } | 141 | } |
142 | pub(crate) fn fetch_build_data_completed(&mut self) { | 142 | pub(crate) fn fetch_build_data_completed( |
143 | self.fetch_build_data_queue.op_completed(()) | 143 | &mut self, |
144 | build_data: anyhow::Result<BuildDataResult>, | ||
145 | ) { | ||
146 | self.fetch_build_data_queue.op_completed(Some(build_data)) | ||
144 | } | 147 | } |
145 | 148 | ||
146 | pub(crate) fn fetch_workspaces_request(&mut self) { | 149 | pub(crate) fn fetch_workspaces_request(&mut self) { |
@@ -194,54 +197,55 @@ impl GlobalState { | |||
194 | } | 197 | } |
195 | }); | 198 | }); |
196 | } | 199 | } |
197 | pub(crate) fn fetch_workspaces_completed(&mut self) { | 200 | pub(crate) fn fetch_workspaces_completed( |
198 | self.fetch_workspaces_queue.op_completed(()) | ||
199 | } | ||
200 | |||
201 | pub(crate) fn switch_workspaces( | ||
202 | &mut self, | 201 | &mut self, |
203 | workspaces: Vec<anyhow::Result<ProjectWorkspace>>, | 202 | workspaces: Vec<anyhow::Result<ProjectWorkspace>>, |
204 | workspace_build_data: Option<anyhow::Result<BuildDataResult>>, | ||
205 | ) { | 203 | ) { |
204 | self.fetch_workspaces_queue.op_completed(workspaces) | ||
205 | } | ||
206 | |||
207 | pub(crate) fn switch_workspaces(&mut self) { | ||
206 | let _p = profile::span("GlobalState::switch_workspaces"); | 208 | let _p = profile::span("GlobalState::switch_workspaces"); |
209 | let workspaces = self.fetch_workspaces_queue.last_op_result(); | ||
207 | log::info!("will switch workspaces: {:?}", workspaces); | 210 | log::info!("will switch workspaces: {:?}", workspaces); |
208 | 211 | ||
209 | let mut has_errors = false; | 212 | let mut error_message = None; |
210 | let workspaces = workspaces | 213 | let workspaces = workspaces |
211 | .into_iter() | 214 | .iter() |
212 | .filter_map(|res| { | 215 | .filter_map(|res| match res { |
213 | res.map_err(|err| { | 216 | Ok(it) => Some(it.clone()), |
214 | has_errors = true; | 217 | Err(err) => { |
215 | log::error!("failed to load workspace: {:#}", err); | 218 | log::error!("failed to load workspace: {:#}", err); |
216 | if self.workspaces.is_empty() { | 219 | let message = error_message.get_or_insert_with(String::new); |
217 | self.show_message( | 220 | stdx::format_to!( |
218 | lsp_types::MessageType::Error, | 221 | message, |
219 | format!("rust-analyzer failed to load workspace: {:#}", err), | 222 | "rust-analyzer failed to load workspace: {:#}\n", |
220 | ); | 223 | err |
221 | } | 224 | ); |
222 | }) | 225 | None |
223 | .ok() | 226 | } |
224 | }) | 227 | }) |
225 | .collect::<Vec<_>>(); | 228 | .collect::<Vec<_>>(); |
226 | 229 | ||
227 | let workspace_build_data = match workspace_build_data { | 230 | let workspace_build_data = match self.fetch_build_data_queue.last_op_result() { |
228 | Some(Ok(it)) => Some(it), | 231 | Some(Ok(it)) => Some(it.clone()), |
232 | None => None, | ||
229 | Some(Err(err)) => { | 233 | Some(Err(err)) => { |
230 | log::error!("failed to fetch build data: {:#}", err); | 234 | log::error!("failed to fetch build data: {:#}", err); |
231 | self.show_message( | 235 | let message = error_message.get_or_insert_with(String::new); |
232 | lsp_types::MessageType::Error, | 236 | stdx::format_to!(message, "rust-analyzer failed to fetch build data: {:#}\n", err); |
233 | format!("rust-analyzer failed to fetch build data: {:#}", err), | 237 | None |
234 | ); | ||
235 | return; | ||
236 | } | 238 | } |
237 | None => None, | ||
238 | }; | 239 | }; |
239 | 240 | ||
240 | if *self.workspaces == workspaces && self.workspace_build_data == workspace_build_data { | 241 | if let Some(error_message) = error_message { |
241 | return; | 242 | self.show_message(lsp_types::MessageType::Error, error_message); |
243 | if !self.workspaces.is_empty() { | ||
244 | return; | ||
245 | } | ||
242 | } | 246 | } |
243 | 247 | ||
244 | if !self.workspaces.is_empty() && has_errors { | 248 | if *self.workspaces == workspaces && self.workspace_build_data == workspace_build_data { |
245 | return; | 249 | return; |
246 | } | 250 | } |
247 | 251 | ||
@@ -337,14 +341,6 @@ impl GlobalState { | |||
337 | }; | 341 | }; |
338 | change.set_crate_graph(crate_graph); | 342 | change.set_crate_graph(crate_graph); |
339 | 343 | ||
340 | if self.config.run_build_scripts() && workspace_build_data.is_none() { | ||
341 | let mut collector = BuildDataCollector::default(); | ||
342 | for ws in &workspaces { | ||
343 | ws.collect_build_data_configs(&mut collector); | ||
344 | } | ||
345 | self.fetch_build_data_request(collector) | ||
346 | } | ||
347 | |||
348 | self.source_root_config = project_folders.source_root_config; | 344 | self.source_root_config = project_folders.source_root_config; |
349 | self.workspaces = Arc::new(workspaces); | 345 | self.workspaces = Arc::new(workspaces); |
350 | self.workspace_build_data = workspace_build_data; | 346 | self.workspace_build_data = workspace_build_data; |