@@ -93,7 +93,7 @@ private void Sinks_ProjectRemoved(object sender, IProjectEventArgs e)
9393
9494            Debug . Assert ( e . ProjectId  !=  null ) ; 
9595
96-             RemoveProject ( e . ProjectId ) ; 
96+             RemoveProject ( e . ProjectId ,   true ) ; 
9797            OnParseRequested ( sender ) ; 
9898        } 
9999
@@ -224,27 +224,14 @@ public void RefreshProjects()
224224            } 
225225        } 
226226
227-         private  void  RemoveProject ( string  projectId ) 
227+         private  void  RemoveProject ( string  projectId ,   bool   notifyStateChanged   =   false ) 
228228        { 
229-             VBProject  project  =  null ; 
230-             foreach  ( var  p  in  Projects ) 
231-             { 
232-                 if  ( p . HelpFile  ==  projectId ) 
233-                 { 
234-                     project  =  p ; 
235-                     break ; 
236-                 } 
237-             } 
238- 
239229            if  ( _projects . ContainsKey ( projectId ) ) 
240230            { 
241231                _projects . Remove ( projectId ) ; 
242232            } 
243233
244-             if  ( project  !=  null ) 
245-             { 
246-                 ClearStateCache ( project ) ; 
247-             } 
234+             ClearStateCache ( projectId ,  notifyStateChanged ) ; 
248235        } 
249236
250237        public  List < VBProject >  Projects 
@@ -654,20 +641,30 @@ public void AddDeclaration(Declaration declaration)
654641            } 
655642        } 
656643
657-         private  void  ClearStateCache ( VBProject   project ,  bool  notifyStateChanged  =  false ) 
644+         private  void  ClearStateCache ( string   projectId ,  bool  notifyStateChanged  =  false ) 
658645        { 
659646            try 
660647            { 
661-                 foreach  ( VBComponent  component  in  project . VBComponents ) 
648+                 var  qualifiedModuleName  =  new  QualifiedModuleName ( ) ; 
649+ 
650+                 foreach  ( var  moduleState  in  _moduleStates ) 
662651                { 
663-                     while  ( ! ClearStateCache ( component ) ) 
652+                     if  ( moduleState . Key . ProjectId  ==  projectId  &&  moduleState . Key . Component  !=  null ) 
653+                     { 
654+                         while  ( ! ClearStateCache ( moduleState . Key . Component ) ) 
655+                         { 
656+                             // until Hell freezes over? 
657+                         } 
658+                     } 
659+                     else  if  ( moduleState . Key . ProjectId  ==  projectId  &&  moduleState . Key . Component  ==  null ) 
664660                    { 
665-                         // until Hell freezes over? 
661+                         // store project module name 
662+                         qualifiedModuleName  =  moduleState . Key ; 
666663                    } 
667664                } 
668665
669666                ModuleState  state ; 
670-                 if  ( _moduleStates . TryRemove ( new   QualifiedModuleName ( project ) ,  out  state ) ) 
667+                 if  ( _moduleStates . TryRemove ( qualifiedModuleName ,  out  state ) ) 
671668                { 
672669                    state . Dispose ( ) ; 
673670                } 
0 commit comments