@@ -72,9 +72,10 @@ impl GlobalState {
72
72
status. message =
73
73
Some ( "Reload required due to source changes of a procedural macro." . into ( ) )
74
74
}
75
- if let Some ( error ) = self . fetch_build_data_error ( ) {
75
+ if let Err ( _ ) = self . fetch_build_data_error ( ) {
76
76
status. health = lsp_ext:: Health :: Warning ;
77
- status. message = Some ( error)
77
+ status. message =
78
+ Some ( "Failed to run build scripts of some packages, check the logs." . to_string ( ) ) ;
78
79
}
79
80
if !self . config . cargo_autoreload ( )
80
81
&& self . is_quiescent ( )
@@ -84,7 +85,7 @@ impl GlobalState {
84
85
status. message = Some ( "Workspace reload required" . to_string ( ) )
85
86
}
86
87
87
- if let Some ( error) = self . fetch_workspace_error ( ) {
88
+ if let Err ( error) = self . fetch_workspace_error ( ) {
88
89
status. health = lsp_ext:: Health :: Error ;
89
90
status. message = Some ( error)
90
91
}
@@ -167,17 +168,20 @@ impl GlobalState {
167
168
let _p = profile:: span ( "GlobalState::switch_workspaces" ) ;
168
169
tracing:: info!( "will switch workspaces" ) ;
169
170
170
- if let Some ( error_message) = self . fetch_workspace_error ( ) {
171
- tracing :: error! ( "failed to switch workspaces: {}" , error_message ) ;
171
+ if let Err ( error_message) = self . fetch_workspace_error ( ) {
172
+ self . show_and_log_error ( error_message , None ) ;
172
173
if !self . workspaces . is_empty ( ) {
173
174
// It only makes sense to switch to a partially broken workspace
174
175
// if we don't have any workspace at all yet.
175
176
return ;
176
177
}
177
178
}
178
179
179
- if let Some ( error_message) = self . fetch_build_data_error ( ) {
180
- tracing:: error!( "failed to switch build data: {}" , error_message) ;
180
+ if let Err ( error) = self . fetch_build_data_error ( ) {
181
+ self . show_and_log_error (
182
+ "rust-analyzer failed to run build scripts" . to_string ( ) ,
183
+ Some ( error) ,
184
+ ) ;
181
185
}
182
186
183
187
let workspaces = self
@@ -277,20 +281,18 @@ impl GlobalState {
277
281
let project_folders = ProjectFolders :: new ( & self . workspaces , & files_config. exclude ) ;
278
282
279
283
if self . proc_macro_client . is_none ( ) {
280
- self . proc_macro_client = match self . config . proc_macro_srv ( ) {
281
- None => None ,
282
- Some ( ( path, args) ) => match ProcMacroServer :: spawn ( path. clone ( ) , args) {
283
- Ok ( it) => Some ( it) ,
284
+ if let Some ( ( path, args) ) = self . config . proc_macro_srv ( ) {
285
+ match ProcMacroServer :: spawn ( path. clone ( ) , args) {
286
+ Ok ( it) => self . proc_macro_client = Some ( it) ,
284
287
Err ( err) => {
285
288
tracing:: error!(
286
289
"Failed to run proc_macro_srv from path {}, error: {:?}" ,
287
290
path. display( ) ,
288
291
err
289
292
) ;
290
- None
291
293
}
292
- } ,
293
- } ;
294
+ }
295
+ }
294
296
}
295
297
296
298
let watch = match files_config. watcher {
@@ -348,7 +350,7 @@ impl GlobalState {
348
350
tracing:: info!( "did switch workspaces" ) ;
349
351
}
350
352
351
- fn fetch_workspace_error ( & self ) -> Option < String > {
353
+ fn fetch_workspace_error ( & self ) -> Result < ( ) , String > {
352
354
let mut buf = String :: new ( ) ;
353
355
354
356
for ws in self . fetch_workspaces_queue . last_op_result ( ) {
@@ -358,35 +360,30 @@ impl GlobalState {
358
360
}
359
361
360
362
if buf. is_empty ( ) {
361
- return None ;
363
+ return Ok ( ( ) ) ;
362
364
}
363
365
364
- Some ( buf)
366
+ Err ( buf)
365
367
}
366
368
367
- fn fetch_build_data_error ( & self ) -> Option < String > {
368
- let mut buf = "rust-analyzer failed to run build scripts:\n " . to_string ( ) ;
369
- let mut has_errors = false ;
369
+ fn fetch_build_data_error ( & self ) -> Result < ( ) , String > {
370
+ let mut buf = String :: new ( ) ;
370
371
371
372
for ws in & self . fetch_build_data_queue . last_op_result ( ) . 1 {
372
373
match ws {
373
- Ok ( data) => {
374
- if let Some ( err) = data. error ( ) {
375
- has_errors = true ;
376
- stdx:: format_to!( buf, "{:#}\n " , err) ;
377
- }
378
- }
379
- Err ( err) => {
380
- has_errors = true ;
381
- stdx:: format_to!( buf, "{:#}\n " , err) ;
382
- }
374
+ Ok ( data) => match data. error ( ) {
375
+ Some ( stderr) => stdx:: format_to!( buf, "{:#}\n " , stderr) ,
376
+ _ => ( ) ,
377
+ } ,
378
+ // io errors
379
+ Err ( err) => stdx:: format_to!( buf, "{:#}\n " , err) ,
383
380
}
384
381
}
385
382
386
- if has_errors {
387
- Some ( buf )
383
+ if buf . is_empty ( ) {
384
+ Ok ( ( ) )
388
385
} else {
389
- None
386
+ Err ( buf )
390
387
}
391
388
}
392
389
0 commit comments