Skip to content

Commit f384dff

Browse files
committed
<s>solved</s> *circumvented* project equality problem
1 parent 470a845 commit f384dff

File tree

6 files changed

+53
-11
lines changed

6 files changed

+53
-11
lines changed

RetailCoder.VBE/Common/Hotkeys/Hotkey.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ private void HookKey(Keys key, uint shift)
8383
var success = User32.RegisterHotKey(_hWndVbe, hookId, shift, (uint)key);
8484
if (!success)
8585
{
86-
throw new Win32Exception("HotKey was not registered.");
86+
Debug.WriteLine("Hotkey ({0}) not registered.", key);
87+
//throw new Win32Exception("HotKey was not registered.");
8788
}
8889

8990
HotkeyInfo = new HotkeyInfo(hookId, Combo);

Rubberduck.Parsing/Symbols/DeclarationFinder.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@ public DeclarationFinder(IReadOnlyList<Declaration> declarations, IEnumerable<Co
1717
_comments = comments.GroupBy(node => node.QualifiedSelection.QualifiedName)
1818
.ToDictionary(grouping => grouping.Key, grouping => grouping.ToArray());
1919

20-
_declarationsByName = declarations.GroupBy(declaration => declaration.IdentifierName)
21-
.ToDictionary(grouping => grouping.Key, grouping => grouping.ToArray());
20+
_declarationsByName = declarations.GroupBy(declaration => new
21+
{
22+
IdentifierName = declaration.Project != null &&
23+
declaration.DeclarationType == DeclarationType.Project
24+
? declaration.Project.Name
25+
: declaration.IdentifierName
26+
})
27+
.ToDictionary(grouping => grouping.Key.IdentifierName, grouping => grouping.ToArray());
2228
}
2329

2430
private readonly HashSet<Accessibility> _projectScopePublicModifiers =

Rubberduck.Parsing/Symbols/DeclarationSymbolsListener.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Rubberduck.Parsing.Nodes;
99
using Rubberduck.Parsing.VBA;
1010
using Rubberduck.VBEditor;
11+
using Rubberduck.VBEditor.Extensions;
1112

1213
namespace Rubberduck.Parsing.Symbols
1314
{
@@ -37,9 +38,7 @@ public DeclarationSymbolsListener(QualifiedModuleName qualifiedName, Accessibili
3738
var project = _qualifiedName.Component.Collection.Parent;
3839
var projectQualifiedName = new QualifiedModuleName(project);
3940

40-
_projectDeclaration = new Declaration(
41-
projectQualifiedName.QualifyMemberName(project.Name),
42-
null, (Declaration)null, project.Name, false, false, Accessibility.Implicit, DeclarationType.Project, null, Selection.Home, false);
41+
_projectDeclaration = CreateProjectDeclaration(projectQualifiedName, project);
4342

4443
var key = Tuple.Create(_qualifiedName.ComponentName, declarationType);
4544
var moduleAttributes = attributes.ContainsKey(key)
@@ -61,6 +60,17 @@ public DeclarationSymbolsListener(QualifiedModuleName qualifiedName, Accessibili
6160
SetCurrentScope();
6261
}
6362

63+
private static Declaration CreateProjectDeclaration(QualifiedModuleName projectQualifiedName, VBProject project)
64+
{
65+
var projectName = project.ProjectName();
66+
67+
var declaration = new Declaration(
68+
projectQualifiedName.QualifyMemberName(projectName),
69+
null, (Declaration) null, projectName, false, false, Accessibility.Implicit, DeclarationType.Project, null,
70+
Selection.Home, false);
71+
return declaration;
72+
}
73+
6474
private string FindAnnotations()
6575
{
6676
if (_comments == null)

Rubberduck.VBEEditor/ActiveCodePaneEditor.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public void SetSelection(QualifiedSelection selection)
4646

4747
public string GetLines(Selection selection)
4848
{
49-
// ReSharper disable once UseIndexedProperty
5049
return Editor.get_Lines(selection.StartLine, selection.LineCount);
5150
}
5251

Rubberduck.VBEEditor/Extensions/VbProjectExtensions.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,31 @@ namespace Rubberduck.VBEditor.Extensions
77
{
88
public static class ProjectExtensions
99
{
10+
public static string ProjectName(this VBProject project)
11+
{
12+
var projectName = project.Name;
13+
var documentModule = project
14+
.VBComponents.Cast<VBComponent>()
15+
.FirstOrDefault(item => item.Type == vbext_ComponentType.vbext_ct_Document);
16+
17+
if (documentModule != null)
18+
{
19+
var hostDocumentNameProperty = documentModule.Properties.Item("Name");
20+
if (hostDocumentNameProperty != null)
21+
{
22+
projectName += string.Format(" ({0})", hostDocumentNameProperty.Value);
23+
}
24+
}
25+
26+
return projectName;
27+
}
28+
29+
public static string ProjectName(this VBComponent component)
30+
{
31+
var project = component.Collection.Parent;
32+
return project.ProjectName();
33+
}
34+
1035
public static IEnumerable<string> ComponentNames(this VBProject project)
1136
{
1237
foreach (VBComponent component in project.VBComponents)

Rubberduck.VBEEditor/QualifiedModuleName.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using Microsoft.Vbe.Interop;
3+
using Rubberduck.VBEditor.Extensions;
34

45
namespace Rubberduck.VBEditor
56
{
@@ -13,7 +14,7 @@ public QualifiedModuleName(VBProject project)
1314
_component = null;
1415
_componentName = null;
1516
_project = project;
16-
_projectName = project.Name;
17+
_projectName = project.ProjectName();
1718
_contentHashCode = 0;
1819
}
1920

@@ -24,7 +25,7 @@ public QualifiedModuleName(VBComponent component)
2425
_component = component;
2526
_componentName = component == null ? string.Empty : component.Name;
2627
_project = component == null ? null : component.Collection.Parent;
27-
_projectName = component == null ? string.Empty : component.Collection.Parent.Name;
28+
_projectName = component == null ? string.Empty : component.ProjectName();
2829

2930
_contentHashCode = 0;
3031
if (component == null)
@@ -92,10 +93,10 @@ public override bool Equals(object obj)
9293
var other = (QualifiedModuleName)obj;
9394
if (other.Component == null)
9495
{
95-
return other.Project == Project && other.ComponentName == ComponentName;
96+
return other.ProjectName == ProjectName && other.ComponentName == ComponentName;
9697
}
9798

98-
var result = other.Project == Project // ugh. not reliable...
99+
var result = other.ProjectName == ProjectName
99100
&& other.ComponentName == ComponentName
100101
&& other._contentHashCode == _contentHashCode;
101102
return result;

0 commit comments

Comments
 (0)