@@ -251,7 +251,7 @@ impl GlobalState {
251
251
(
252
252
crate_id,
253
253
res. map_or_else (
254
- || Err ( "proc macro crate is missing dylib" . to_owned ( ) ) ,
254
+ |_ | Err ( "proc macro crate is missing dylib" . to_owned ( ) ) ,
255
255
|( crate_name, path) | {
256
256
progress ( path. display ( ) . to_string ( ) ) ;
257
257
load_proc_macro (
@@ -296,25 +296,11 @@ impl GlobalState {
296
296
let workspaces =
297
297
workspaces. iter ( ) . filter_map ( |res| res. as_ref ( ) . ok ( ) . cloned ( ) ) . collect :: < Vec < _ > > ( ) ;
298
298
299
- // `different_workspaces` is used to determine whether to spawn a a new proc macro server for
300
- // a newly-added rust workspace (most commonly sourced from a `rust-project.json`). While the
301
- // algorithm to find the new workspaces is quadratic, we generally expect that the number of total
302
- // workspaces to remain in the low single digits. the `cloned_workspace` is needed for borrowck
303
- // reasons.
304
- let cloned_workspaces = workspaces. clone ( ) ;
305
- let different_workspaces = cloned_workspaces
306
- . iter ( )
307
- . filter ( |ws| {
308
- !self
309
- . workspaces
310
- . iter ( )
311
- . find ( |existing_ws| ws. eq_ignore_build_data ( & existing_ws) )
312
- . is_some ( )
313
- } )
314
- . collect :: < Vec < _ > > ( ) ;
315
- let same_workspaces = different_workspaces. is_empty ( ) ;
316
-
317
- tracing:: debug!( current_workspaces = ?self . workspaces, new_workspaces = ?workspaces, ?same_workspaces, "comparing workspaces" ) ;
299
+ let same_workspaces = workspaces. len ( ) == self . workspaces . len ( )
300
+ && workspaces
301
+ . iter ( )
302
+ . zip ( self . workspaces . iter ( ) )
303
+ . all ( |( l, r) | l. eq_ignore_build_data ( r) ) ;
318
304
319
305
if same_workspaces {
320
306
let ( workspaces, build_scripts) = self . fetch_build_data_queue . last_op_result ( ) ;
@@ -384,7 +370,7 @@ impl GlobalState {
384
370
let files_config = self . config . files ( ) ;
385
371
let project_folders = ProjectFolders :: new ( & self . workspaces , & files_config. exclude ) ;
386
372
387
- if self . proc_macro_clients . is_empty ( ) || !different_workspaces . is_empty ( ) {
373
+ if self . proc_macro_clients . is_empty ( ) || !same_workspaces {
388
374
if let Some ( ( path, path_manually_set) ) = self . config . proc_macro_srv ( ) {
389
375
tracing:: info!( "Spawning proc-macro servers" ) ;
390
376
self . proc_macro_clients = self
@@ -462,31 +448,8 @@ impl GlobalState {
462
448
} ;
463
449
let mut change = Change :: new ( ) ;
464
450
465
- // `self.fetch_proc_macros_queue.request_op(cause, proc_macro_paths)` is only called in
466
- // when `switch_workspaces` is called _without_ changing workspaces. This typically occurs
467
- // when build scripts have finishing building, but when rust-analyzer is used with a
468
- // rust-project.json, the build scripts have already been built by the external build system
469
- // that generated the `rust-project.json`.
470
-
471
- // Therefore, in order to allow _new_ workspaces added via rust-project.json (e.g., after
472
- // a workspace was already added), we check whether this is the same workspace _or_
473
- // if any of the new workspaces is a `rust-project.json`.
474
- //
475
- // The else branch is used to provide better diagnostics to users while procedural macros
476
- // are still being built.
477
- if same_workspaces || different_workspaces. iter ( ) . any ( |ws| ws. is_json ( ) ) {
478
- if self . config . expand_proc_macros ( ) {
479
- self . fetch_proc_macros_queue . request_op ( cause, proc_macro_paths) ;
480
- }
481
- } else {
482
- // Set up errors for proc-macros upfront that we haven't run build scripts yet
483
- let mut proc_macros = FxHashMap :: default ( ) ;
484
- for paths in proc_macro_paths {
485
- proc_macros. extend ( paths. into_iter ( ) . map ( move |( crate_id, _) | {
486
- ( crate_id, Err ( "crate has not yet been build" . to_owned ( ) ) )
487
- } ) ) ;
488
- }
489
- change. set_proc_macros ( proc_macros) ;
451
+ if self . config . expand_proc_macros ( ) {
452
+ self . fetch_proc_macros_queue . request_op ( cause, proc_macro_paths) ;
490
453
}
491
454
change. set_crate_graph ( crate_graph) ;
492
455
self . analysis_host . apply_change ( change) ;
0 commit comments