@@ -263,6 +263,8 @@ pub struct InitActionContext<O: Output> {
263263 // the root workspaces
264264 pub workspace_roots : Arc < Mutex < Vec < Workspace > > > ,
265265
266+ pub cached_path_resolver : Arc < Mutex < Option < PathResolver > > > ,
267+
266268 // directly opened files
267269 pub direct_opens : Arc < Mutex < HashSet < CanonPath > > > ,
268270 pub compilation_info : Arc < Mutex < CompilationInfoStorage > > ,
@@ -378,6 +380,7 @@ impl <O: Output> InitActionContext<O> {
378380 config,
379381 lint_config : Arc :: new ( Mutex :: new ( LintCfg :: default ( ) ) ) ,
380382 jobs : Arc :: default ( ) ,
383+ cached_path_resolver : Arc :: default ( ) ,
381384 direct_opens : Arc :: default ( ) ,
382385 quiescent : Arc :: new ( AtomicBool :: new ( false ) ) ,
383386 prev_changes : Arc :: default ( ) ,
@@ -419,12 +422,17 @@ impl <O: Output> InitActionContext<O> {
419422
420423 pub fn update_workspaces ( & self ,
421424 mut add : Vec < Workspace > ,
422- remove : Vec < Workspace > ) {
425+ remove : Vec < Workspace > ,
426+ out : & O ) {
427+ let any_change = !( add. is_empty ( ) && remove. is_empty ( ) ) ;
423428 if let Ok ( mut workspaces) = self . workspace_roots . lock ( ) {
424429 workspaces. retain ( |workspace|
425430 remove. iter ( ) . all ( |rem|rem != workspace) ) ;
426431 workspaces. append ( & mut add) ;
427432 }
433+ if any_change {
434+ self . update_compilation_info ( out) ;
435+ }
428436 }
429437
430438 fn update_linter_config ( & self , out : & O ) {
@@ -445,6 +453,11 @@ impl <O: Output> InitActionContext<O> {
445453 trace ! ( "Updating compile info" ) ;
446454 if let Ok ( config) = self . config . lock ( ) {
447455 if let Some ( compile_info) = & config. compile_info_path {
456+ // Ensure resolver exists
457+ self . construct_resolver ( ) ;
458+ // And then remove it from storage (invalidates it)
459+ let old_resolver = self . cached_path_resolver . lock ( )
460+ . expect ( "Failed to grab resolver" ) . take ( ) . unwrap ( ) ;
448461 if let Some ( canon_path) = CanonPath :: from_path_buf (
449462 compile_info. clone ( ) ) {
450463 let workspaces = self . workspace_roots . lock ( ) . unwrap ( ) ;
@@ -468,8 +481,7 @@ impl <O: Output> InitActionContext<O> {
468481 * ci = compilation_info;
469482 }
470483 self . analysis . lock ( ) . unwrap ( )
471- . update_all_context_dependencies (
472- self . construct_resolver ( ) ) ;
484+ . update_all_context_dependencies ( old_resolver) ;
473485 } ,
474486 Err ( e) => {
475487 error ! ( "Failed to update compilation info: {}" , e) ;
@@ -776,6 +788,10 @@ impl <O: Output> InitActionContext<O> {
776788 }
777789
778790 pub fn construct_resolver ( & self ) -> PathResolver {
791+ if let Some ( resolver) = self . cached_path_resolver . lock ( )
792+ . unwrap ( ) . as_ref ( ) {
793+ return resolver. clone ( ) ;
794+ }
779795 trace ! ( "About to construct resolver" ) ;
780796 let mut toret: PathResolver =
781797 self . client_capabilities . root . clone ( ) . into ( ) ;
@@ -788,6 +804,7 @@ impl <O: Output> InitActionContext<O> {
788804 . into_iter ( ) . collect ( ) ) )
789805 . collect ( ) ) ;
790806 trace ! ( "Constructed resolver: {:?}" , toret) ;
807+ * self . cached_path_resolver . lock ( ) . unwrap ( ) = Some ( toret. clone ( ) ) ;
791808 toret
792809 }
793810
0 commit comments