Skip to content

Commit f411c31

Browse files
committed
Merge pull request #1294 from retailcoder/next
fixed ProjectName issues
2 parents 2edb655 + db4bdf9 commit f411c31

File tree

7 files changed

+36
-16
lines changed

7 files changed

+36
-16
lines changed

RetailCoder.VBE/App.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ public void Startup()
8484
{
8585
CleanReloadConfig();
8686

87+
foreach (var project in _vbe.VBProjects.Cast<VBProject>())
88+
{
89+
_parser.State.AddProject(project);
90+
}
91+
8792
_appMenus.Initialize();
8893
_appMenus.Localize();
8994

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerProjectViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private static IEnumerable<CodeExplorerItemViewModel> FindFolders(IEnumerable<De
8383
public override BitmapImage CollapsedIcon { get { return _icon; } }
8484
public override BitmapImage ExpandedIcon { get { return _icon; } }
8585

86-
public override string Name { get { return _declaration.CustomFolder; } }
86+
public override string Name { get { return _declaration.IdentifierName; } }
8787
public override QualifiedSelection? QualifiedSelection { get { return _declaration.QualifiedSelection; } }
8888
}
8989
}

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private void ParserState_StateChanged(object sender, EventArgs e)
8787

8888
Debug.WriteLine("Creating Code Explorer model...");
8989
var userDeclarations = _state.AllUserDeclarations
90-
.GroupBy(declaration => declaration.Project)
90+
.GroupBy(declaration => declaration.ProjectName)
9191
.Where(grouping => grouping.Key != null)
9292
.ToList();
9393

Rubberduck.Parsing/Symbols/Declaration.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ public Declaration(QualifiedMemberName qualifiedName, Declaration parentDeclarat
6262
string result;
6363
if (string.IsNullOrEmpty(ns))
6464
{
65-
result = _projectName;
65+
result = _qualifiedName.QualifiedModuleName.Project == null
66+
? _projectName
67+
: _qualifiedName.QualifiedModuleName.Project.Name;
6668
}
6769
else
6870
{

Rubberduck.Parsing/VBA/RubberduckParserState.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Rubberduck.Parsing.Nodes;
1212
using Rubberduck.Parsing.Symbols;
1313
using Rubberduck.VBEditor;
14+
using Rubberduck.VBEditor.Extensions;
1415

1516
namespace 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;

Rubberduck.VBEEditor/QualifiedMemberName.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@ public override string ToString()
2323

2424
public override int GetHashCode()
2525
{
26-
// note: fingers crossed here
27-
return (_qualifiedModuleName.GetHashCode() + _qualifiedModuleName.ToString() + _memberName).GetHashCode();
26+
unchecked
27+
{
28+
var hash = 17;
29+
hash = hash * 23 + _qualifiedModuleName.GetHashCode();
30+
hash = hash * 23 + _memberName.GetHashCode();
31+
return hash;
32+
}
2833
}
2934

3035
public override bool Equals(object obj)

Rubberduck.VBEEditor/QualifiedModuleName.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,13 @@ public override string ToString()
8181

8282
public override int GetHashCode()
8383
{
84-
return _component == null ? 0 : _component.GetHashCode();
84+
unchecked
85+
{
86+
var hash = 17;
87+
hash = hash * 23 + _projectName.GetHashCode();
88+
hash = hash * 23 + (_component == null ? 0 : _component.GetHashCode());
89+
return hash;
90+
}
8591
}
8692

8793
public override bool Equals(object obj)
@@ -97,8 +103,7 @@ public override bool Equals(object obj)
97103
}
98104

99105
var result = other.ProjectName == ProjectName
100-
&& other.ComponentName == ComponentName
101-
&& other._contentHashCode == _contentHashCode;
106+
&& other.ComponentName == ComponentName;
102107
return result;
103108
}
104109
catch (InvalidCastException)

0 commit comments

Comments
 (0)