@@ -140,7 +140,6 @@ private void Sinks_ProjectAdded(object sender, ProjectEventArgs e)
140140            if  ( ! e . Project . VBE . IsInDesignMode )  {  return ;  } 
141141
142142            Logger . Debug ( "Project '{0}' was added." ,  e . ProjectId ) ; 
143-             RefreshProjects ( _vbe ) ;  // note side-effect: assigns ProjectId/HelpFile 
144143            OnParseRequested ( sender ) ; 
145144        } 
146145
@@ -149,7 +148,6 @@ private void Sinks_ProjectRemoved(object sender, ProjectEventArgs e)
149148            if  ( ! e . Project . VBE . IsInDesignMode )  {  return ;  } 
150149
151150            Debug . Assert ( e . ProjectId  !=  null ) ; 
152-             RemoveProject ( e . ProjectId ,  true ) ; 
153151            OnParseRequested ( sender ) ; 
154152        } 
155153
@@ -164,9 +162,6 @@ private void Sinks_ProjectRenamed(object sender, ProjectRenamedEventArgs e)
164162
165163            Logger . Debug ( "Project {0} was renamed." ,  e . ProjectId ) ; 
166164
167-             RemoveProject ( e . ProjectId ) ; 
168-             RefreshProjects ( e . Project . VBE ) ; 
169- 
170165            OnParseRequested ( sender ) ; 
171166        } 
172167
@@ -207,14 +202,26 @@ private void Sinks_ComponentRenamed(object sender, ComponentRenamedEventArgs e)
207202
208203            Logger . Debug ( "Component '{0}' was renamed to '{1}'." ,  e . OldName ,  e . Component . Name ) ; 
209204
205+             //todo: Find out for which situation this drastic (and problematic) cache invalidation has been introduced. 
206+             if  ( ComponentIsWorksheet ( e ) ) 
207+             { 
208+                 RemoveProject ( e . ProjectId ) ; 
209+                 Logger . Debug ( "Project '{0}' was removed." ,  e . Component . Name ) ; 
210+             } 
211+ 
212+             OnParseRequested ( sender ) ; 
213+         } 
214+ 
215+         private  bool  ComponentIsWorksheet ( ComponentRenamedEventArgs  e ) 
216+         { 
210217            var  componentIsWorksheet  =  false ; 
211218            foreach  ( var  declaration  in  AllUserDeclarations ) 
212219            { 
213220                if  ( declaration . ProjectId  ==  e . ProjectId  && 
214221                    declaration . DeclarationType  ==  DeclarationType . ClassModule  && 
215222                    declaration . IdentifierName  ==  e . OldName ) 
216223                { 
217-                     foreach  ( var  superType  in  ( ( ClassModuleDeclaration )   declaration ) . Supertypes ) 
224+                     foreach  ( var  superType  in  ( ( ClassModuleDeclaration ) declaration ) . Supertypes ) 
218225                    { 
219226                        if  ( superType . IdentifierName  ==  "Worksheet" ) 
220227                        { 
@@ -227,19 +234,7 @@ private void Sinks_ComponentRenamed(object sender, ComponentRenamedEventArgs e)
227234                } 
228235            } 
229236
230-             if  ( componentIsWorksheet ) 
231-             { 
232-                 RemoveProject ( e . ProjectId ) ; 
233-                 Logger . Debug ( "Project '{0}' was removed." ,  e . Component . Name ) ; 
234- 
235-                 RefreshProjects ( e . Project . VBE ) ; 
236-             } 
237-             else 
238-             { 
239-                 RemoveRenamedComponent ( e . ProjectId ,  e . OldName ) ; 
240-             } 
241- 
242-             OnParseRequested ( sender ) ; 
237+             return  componentIsWorksheet ; 
243238        } 
244239
245240        public  void  OnStatusMessageUpdate ( string  message ) 
@@ -850,28 +845,6 @@ public bool ClearStateCache(QualifiedModuleName module, bool notifyStateChanged
850845            return  success ; 
851846        } 
852847
853-         private  bool  RemoveRenamedComponent ( string  projectId ,  string  oldComponentName ) 
854-         { 
855-             var  keys  =  new  List < QualifiedModuleName > ( ) ; 
856-             foreach  ( var  key  in  _moduleStates . Keys ) 
857-             { 
858-                 if  ( key . ComponentName  ==  oldComponentName  &&  key . ProjectId  ==  projectId ) 
859-                 { 
860-                     keys . Add ( key ) ; 
861-                 } 
862-             } 
863- 
864-             var  success  =  keys . Count  !=  0  &&  RemoveKeysFromCollections ( keys ) ; 
865- 
866-             if  ( success ) 
867-             { 
868-                 OnStateChanged ( this ,  ParserState . ResolvedDeclarations ) ;    // trigger test explorer and code explorer updates 
869-                 OnStateChanged ( this ,  ParserState . Ready ) ;    // trigger find all references &c. updates 
870-             } 
871- 
872-             return  success ; 
873-         } 
874- 
875848        private  bool  RemoveKeysFromCollections ( IEnumerable < QualifiedModuleName >  keys ) 
876849        { 
877850            var  success  =  true ; 
0 commit comments