Skip to content

Commit 15fc993

Browse files
authored
Merge pull request #4021 from mansellan/3993
VB6 - Exclude ResFile and RelatedDocument from parse
2 parents da7ef3c + 77b71b7 commit 15fc993

File tree

13 files changed

+95
-28
lines changed

13 files changed

+95
-28
lines changed

Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerComponentViewModel.cs

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using System.Linq;
45
using System.Runtime.InteropServices;
56
using System.Windows.Media.Imaging;
@@ -61,29 +62,44 @@ public CodeExplorerComponentViewModel(CodeExplorerItemViewModel parent, Declarat
6162
var qualifiedModuleName = declaration.QualifiedName.QualifiedModuleName;
6263
try
6364
{
64-
if (qualifiedModuleName.ComponentType == ComponentType.Document)
65+
switch (qualifiedModuleName.ComponentType)
6566
{
66-
var component = _projectsProvider.Component(qualifiedModuleName);
67-
string parenthesizedName;
68-
using (var properties = component.Properties)
69-
{
70-
parenthesizedName = properties["Name"].Value.ToString() ?? String.Empty;
71-
}
72-
73-
if (ContainsBuiltinDocumentPropertiesProperty())
74-
{
75-
CodeExplorerItemViewModel node = this;
76-
while (node.Parent != null)
67+
case ComponentType.Document:
68+
var component = _projectsProvider.Component(qualifiedModuleName);
69+
string parenthesizedName;
70+
using (var properties = component.Properties)
7771
{
78-
node = node.Parent;
72+
parenthesizedName = properties["Name"].Value.ToString() ?? string.Empty;
7973
}
8074

81-
((CodeExplorerProjectViewModel) node).SetParenthesizedName(parenthesizedName);
82-
}
83-
else
84-
{
85-
_name += " (" + parenthesizedName + ")";
86-
}
75+
if (ContainsBuiltinDocumentPropertiesProperty())
76+
{
77+
CodeExplorerItemViewModel node = this;
78+
while (node.Parent != null)
79+
{
80+
node = node.Parent;
81+
}
82+
83+
((CodeExplorerProjectViewModel) node).SetParenthesizedName(parenthesizedName);
84+
}
85+
else
86+
{
87+
_name += " (" + parenthesizedName + ")";
88+
}
89+
break;
90+
91+
case ComponentType.ResFile:
92+
var fileName = Declaration.IdentifierName.Split('\\').Last();
93+
_name = $"{CodeExplorerUI.CodeExplorer_ResourceFileText} ({fileName})";
94+
break;
95+
96+
case ComponentType.RelatedDocument:
97+
_name = $"({Declaration.IdentifierName.Split('\\').Last()})";
98+
break;
99+
100+
default:
101+
_name = Declaration.IdentifierName;
102+
break;
87103
}
88104
}
89105
catch
@@ -183,7 +199,8 @@ private DeclarationType DeclarationType
183199
{ DeclarationType.DocObject, GetImageSource(CodeExplorerUI.document_globe)},
184200
{ DeclarationType.PropPage, GetImageSource(CodeExplorerUI.ui_tab_content)},
185201
{ DeclarationType.ActiveXDesigner, GetImageSource(CodeExplorerUI.pencil_ruler)},
186-
{ DeclarationType.ResFile, GetImageSource(CodeExplorerUI.document_block)}
202+
{ DeclarationType.ResFile, GetImageSource(CodeExplorerUI.document_block)},
203+
{ DeclarationType.RelatedDocument, GetImageSource(CodeExplorerUI.document_import)}
187204
};
188205

189206
private BitmapImage _icon;

Rubberduck.Parsing/VBA/ParseRunner.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ public override void ParseModules(IReadOnlyCollection<QualifiedModuleName> modul
4444
options,
4545
module =>
4646
{
47-
ParseModule(module, token);
47+
if (module.IsParsable)
48+
{
49+
ParseModule(module, token);
50+
}
4851
}
4952
);
5053
}

Rubberduck.Parsing/VBA/ReferenceResolveRunnerBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void ResolveReferences(IReadOnlyCollection<QualifiedModuleName> toResolve
6363
{
6464
token.ThrowIfCancellationRequested();
6565

66-
_toResolve.UnionWith(toResolve);
66+
_toResolve.UnionWith(toResolve.Where(qmn => qmn.IsParsable));
6767
token.ThrowIfCancellationRequested();
6868

6969
if(!_toResolve.Any())

Rubberduck.Parsing/VBA/RubberduckParserState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ private ParserState OverallParserStateFromModuleStates()
418418
var moduleStates = new List<ParserState>();
419419
foreach (var moduleState in _moduleStates)
420420
{
421-
if (string.IsNullOrEmpty(moduleState.Key.ComponentName) || ProjectsProvider.Component(moduleState.Key) == null)
421+
if (string.IsNullOrEmpty(moduleState.Key.ComponentName) || ProjectsProvider.Component(moduleState.Key) == null || !moduleState.Key.IsParsable)
422422
{
423423
continue;
424424
}

Rubberduck.Resources/CodeExplorer/CodeExplorerUI.Designer.cs

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Rubberduck.Resources/CodeExplorer/CodeExplorerUI.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@
223223
<data name="ui_tab_content" type="System.Resources.ResXFileRef, System.Windows.Forms">
224224
<value>..\icons\fugue\ui-tab-content.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
225225
</data>
226+
<data name="document_import" type="System.Resources.ResXFileRef, System.Windows.Forms">
227+
<value>..\Icons\Fugue\document-import.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
228+
</data>
226229
<data name="CodeExplorerDockablePresenter_Caption" xml:space="preserve">
227230
<value>Code Explorer</value>
228231
</data>
688 Bytes
Loading

Rubberduck.Resources/Rubberduck.Resources.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,7 @@
647647
<Resource Include="Icons\Fugue\ui-scroll-pane-form.png" />
648648
<Resource Include="Icons\Fugue\ui-tab-content.png" />
649649
<Content Include="Icons\Custom\PNG\MdiForm.png" />
650+
<Resource Include="Icons\Fugue\document-import.png" />
650651
<Content Include="Splash.png" />
651652
<Resource Include="Icons\Fugue\lock--exclamation.png" />
652653
<Resource Include="Rubberduck.png" />

Rubberduck.VBEEditor/QualifiedModuleName.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static string GetProjectId(IReference reference)
3535

3636
public static int GetModuleContentHash(IVBComponent component)
3737
{
38-
if (component == null || component.IsWrappingNullReference)
38+
if (component == null || component.IsWrappingNullReference || !component.HasCodeModule)
3939
{
4040
return 0;
4141
}
@@ -103,6 +103,7 @@ public QualifiedMemberName QualifyMemberName(string member)
103103

104104
public ComponentType ComponentType { get; }
105105

106+
public bool IsParsable => ComponentType != ComponentType.ResFile && ComponentType != ComponentType.RelatedDocument;
106107
public string ProjectId { get; }
107108

108109
private readonly string _componentName;

Rubberduck.VBEEditor/SafeComWrappers/VB/Abstract/IVBComponent.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace Rubberduck.VBEditor.SafeComWrappers.Abstract
55
public interface IVBComponent : ISafeComWrapper, IEquatable<IVBComponent>
66
{
77
ComponentType Type { get; }
8+
bool HasCodeModule { get; }
89
ICodeModule CodeModule { get; }
910
IVBE VBE { get; }
1011
IVBComponents Collection { get; }

0 commit comments

Comments
 (0)