1111using Rubberduck . Parsing . Nodes ;
1212using Rubberduck . Parsing . Symbols ;
1313using Rubberduck . VBEditor ;
14+ using Rubberduck . VBEditor . Extensions ;
1415
1516namespace Rubberduck . Parsing . VBA
1617{
@@ -44,7 +45,7 @@ public sealed class RubberduckParserState
4445 public event EventHandler < ParseRequestEventArgs > ParseRequest ;
4546
4647 // circumvents VBIDE API's tendency to return a new instance at every parse, which breaks reference equality checks everywhere
47- private readonly IList < VBProject > _projects = new List < VBProject > ( ) ;
48+ private readonly IDictionary < string , VBProject > _projects = new Dictionary < string , VBProject > ( ) ;
4849
4950 private readonly ConcurrentDictionary < QualifiedModuleName , ConcurrentDictionary < Declaration , byte > > _declarations =
5051 new ConcurrentDictionary < QualifiedModuleName , ConcurrentDictionary < Declaration , byte > > ( ) ;
@@ -69,21 +70,23 @@ public sealed class RubberduckParserState
6970
7071 public void AddProject ( VBProject project )
7172 {
72- if ( ! _projects . Contains ( project ) )
73+ var name = project . ProjectName ( ) ;
74+ if ( ! _projects . ContainsKey ( name ) )
7375 {
74- _projects . Add ( project ) ;
76+ _projects . Add ( name , project ) ;
7577 }
7678 }
7779
7880 public void RemoveProject ( VBProject project )
7981 {
80- if ( _projects . Contains ( project ) )
82+ var name = project . ProjectName ( ) ;
83+ if ( _projects . ContainsKey ( name ) )
8184 {
82- _projects . Remove ( project ) ;
85+ _projects . Remove ( name ) ;
8386 }
8487 }
8588
86- public IReadOnlyList < VBProject > Projects { get { return _projects . ToList ( ) ; } }
89+ public IReadOnlyList < VBProject > Projects { get { return _projects . Values . ToList ( ) ; } }
8790
8891 public IReadOnlyList < Tuple < VBComponent , SyntaxErrorException > > ModuleExceptions
8992 {
@@ -304,9 +307,9 @@ public void ClearBuiltInReferences()
304307
305308 public bool ClearDeclarations ( VBComponent component )
306309 {
307- var projectName = component . Collection . Parent . Name ;
310+ var projectName = component . Collection . Parent . ProjectName ( ) ;
308311 var keys = _declarations . Keys . Where ( kvp =>
309- kvp . ProjectName == projectName && kvp . ComponentName == component . Name ) ; // COM object references aren't reliable
312+ kvp . ProjectName == projectName && kvp . ComponentName == component . Name ) ;
310313
311314 var success = true ;
312315 var declarationsRemoved = 0 ;
0 commit comments