Skip to content

Commit 4cd8396

Browse files
committed
Merge pull request #1151 from retailcoder/CodeExplorer
Fixed null target in VariableTypeNotDeclaredInspection (#1150)
2 parents 5f6abf6 + 60eb3f2 commit 4cd8396

File tree

5 files changed

+62
-8
lines changed

5 files changed

+62
-8
lines changed

RetailCoder.VBE/Inspections/VariableTypeNotDeclaredInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
2323
|| item.DeclarationType == DeclarationType.Constant
2424
|| item.DeclarationType == DeclarationType.Parameter)
2525
&& !item.IsTypeSpecified()
26-
select new VariableTypeNotDeclaredInspectionResult(this, item.Context, item.QualifiedName.QualifiedModuleName);
26+
select new VariableTypeNotDeclaredInspectionResult(this, item);
2727

2828
return issues;
2929
}

RetailCoder.VBE/Inspections/VariableTypeNotDeclaredInspectionResult.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using Antlr4.Runtime;
33
using Rubberduck.Parsing.Grammar;
4+
using Rubberduck.Parsing.Symbols;
45
using Rubberduck.VBEditor;
56

67
namespace Rubberduck.Inspections
@@ -9,8 +10,8 @@ public class VariableTypeNotDeclaredInspectionResult : InspectionResultBase
910
{
1011
private readonly IEnumerable<CodeInspectionQuickFix> _quickFixes;
1112

12-
public VariableTypeNotDeclaredInspectionResult(IInspection inspection, ParserRuleContext context, QualifiedModuleName qualifiedName)
13-
: base(inspection, qualifiedName, context)
13+
public VariableTypeNotDeclaredInspectionResult(IInspection inspection, Declaration target)
14+
: base(inspection, target)
1415
{
1516
_quickFixes = new CodeInspectionQuickFix[]
1617
{

Rubberduck.VBEEditor/Extensions/VbeExtensions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static IHostApplication HostApplication(this VBE vbe)
5656
{
5757
const int ctl_view_host = 106;
5858

59-
CommandBarControl host_app_control = vbe.CommandBars.FindControl(MsoControlType.msoControlButton, ctl_view_host);
59+
var host_app_control = vbe.CommandBars.FindControl(MsoControlType.msoControlButton, ctl_view_host);
6060

6161
if (host_app_control == null)
6262
{
@@ -79,12 +79,12 @@ public static IHostApplication HostApplication(this VBE vbe)
7979
case "Microsoft Publisher":
8080
return new PublisherApp();
8181
case "AutoCAD":
82-
return null; //TODO - Confirm the button caption
82+
return new AutoCADApp();
8383
case "CorelDRAW":
84-
return null;
84+
return new CorelDRAWApp();
8585
}
8686
}
87-
return null;
87+
return null;// new FallbackApp(vbe);
8888
}
8989

9090
foreach (var reference in vbe.ActiveVBProject.References.Cast<Reference>()
@@ -111,7 +111,7 @@ public static IHostApplication HostApplication(this VBE vbe)
111111
}
112112
}
113113

114-
return null;
114+
return null; //new FallbackApp(vbe);
115115
}
116116
}
117117
}

Rubberduck.VBEEditor/Rubberduck.VBEditor.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
<Compile Include="VBEHost\AccessApp.cs" />
107107
<Compile Include="VBEHost\CorelDRAWApp.cs" />
108108
<Compile Include="VBEHost\ExcelApp.cs" />
109+
<Compile Include="VBEHost\FallbackApp.cs" />
109110
<Compile Include="VBEHost\HostApplicationBase.cs" />
110111
<Compile Include="VBEHost\IHostApplication.cs" />
111112
<Compile Include="VBEHost\OutlookApp.cs" />
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.Diagnostics;
3+
using Microsoft.Office.Core;
4+
using Microsoft.Vbe.Interop;
5+
using Rubberduck.VBEditor.VBEInterfaces.RubberduckCodePane;
6+
7+
namespace Rubberduck.VBEditor.VBEHost
8+
{
9+
public class FallbackApp : IHostApplication
10+
{
11+
private readonly VBE _vbe;
12+
private readonly CommandBarButton _runButton;
13+
14+
private const int DebugCommandBarId = 4;
15+
private const int RunMacroCommand = 186;
16+
17+
public FallbackApp(VBE vbe)
18+
{
19+
_vbe = vbe;
20+
var mainCommandBar = _vbe.CommandBars[DebugCommandBarId];
21+
_runButton = (CommandBarButton)mainCommandBar.FindControl(Id: RunMacroCommand);
22+
}
23+
24+
public void Run(QualifiedMemberName qualifiedMemberName)
25+
{
26+
var component = qualifiedMemberName.QualifiedModuleName.Component;
27+
var line = component.CodeModule.get_ProcBodyLine(qualifiedMemberName.MemberName, vbext_ProcKind.vbext_pk_Proc);
28+
29+
component.CodeModule.CodePane.SetSelection(line, 1, line, 1);
30+
component.CodeModule.CodePane.ForceFocus();
31+
32+
_runButton.Execute();
33+
// note: this can't work... because the .Execute() call isn't blocking, so method returns before test method actually runs.
34+
}
35+
36+
public TimeSpan TimedMethodCall(QualifiedMemberName qualifiedMemberName)
37+
{
38+
var stopwatch = Stopwatch.StartNew();
39+
40+
Run(qualifiedMemberName);
41+
42+
stopwatch.Stop();
43+
return stopwatch.Elapsed;
44+
}
45+
46+
public string ApplicationName { get { return "(unknown)"; } }
47+
48+
public void Dispose()
49+
{
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)