@@ -139,8 +139,11 @@ impl GlobalState {
139
139
sender. send ( Task :: FetchBuildData ( BuildDataProgress :: End ( res) ) ) . unwrap ( ) ;
140
140
} ) ;
141
141
}
142
- pub ( crate ) fn fetch_build_data_completed ( & mut self ) {
143
- self . fetch_build_data_queue . op_completed ( ( ) )
142
+ pub ( crate ) fn fetch_build_data_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
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 ) {
198
- self . fetch_workspaces_queue . op_completed ( ( ) )
199
- }
200
-
201
- pub ( crate ) fn switch_workspaces (
200
+ pub ( crate ) fn fetch_workspaces_completed (
202
201
& mut self ,
203
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
208
let _p = profile:: span ( "GlobalState::switch_workspaces" ) ;
209
+ let workspaces = self . fetch_workspaces_queue . last_op_result ( ) ;
207
210
log:: info!( "will switch workspaces: {:?}" , workspaces) ;
208
211
209
- let mut has_errors = false ;
212
+ let mut error_message = None ;
210
213
let workspaces = workspaces
211
- . into_iter ( )
212
- . filter_map ( |res| {
213
- res . map_err ( |err| {
214
- has_errors = true ;
214
+ . iter ( )
215
+ . filter_map ( |res| match res {
216
+ Ok ( it ) => Some ( it . clone ( ) ) ,
217
+ Err ( err ) => {
215
218
log:: error!( "failed to load workspace: {:#}" , err) ;
216
- if self . workspaces . is_empty ( ) {
217
- self . show_message (
218
- lsp_types :: MessageType :: Error ,
219
- format ! ( "rust-analyzer failed to load workspace: {:#}" , err ) ,
220
- ) ;
221
- }
222
- } )
223
- . ok ( )
219
+ let message = error_message . get_or_insert_with ( String :: new ) ;
220
+ stdx :: format_to! (
221
+ message ,
222
+ "rust-analyzer failed to load workspace: {:#}\n " ,
223
+ err
224
+ ) ;
225
+ None
226
+ }
224
227
} )
225
228
. collect :: < Vec < _ > > ( ) ;
226
229
227
- let workspace_build_data = match workspace_build_data {
228
- Some ( Ok ( it) ) => Some ( it) ,
230
+ let workspace_build_data = match self . fetch_build_data_queue . last_op_result ( ) {
231
+ Some ( Ok ( it) ) => Some ( it. clone ( ) ) ,
232
+ None => None ,
229
233
Some ( Err ( err) ) => {
230
234
log:: error!( "failed to fetch build data: {:#}" , err) ;
231
- self . show_message (
232
- lsp_types:: MessageType :: Error ,
233
- format ! ( "rust-analyzer failed to fetch build data: {:#}" , err) ,
234
- ) ;
235
- return ;
235
+ let message = error_message. get_or_insert_with ( String :: new) ;
236
+ stdx:: format_to!( message, "rust-analyzer failed to fetch build data: {:#}\n " , err) ;
237
+ None
236
238
}
237
- None => None ,
238
239
} ;
239
240
240
- if * self . workspaces == workspaces && self . workspace_build_data == workspace_build_data {
241
- return ;
241
+ if let Some ( error_message) = error_message {
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
249
return ;
246
250
}
247
251
@@ -337,14 +341,6 @@ impl GlobalState {
337
341
} ;
338
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
344
self . source_root_config = project_folders. source_root_config ;
349
345
self . workspaces = Arc :: new ( workspaces) ;
350
346
self . workspace_build_data = workspace_build_data;
0 commit comments