Skip to content

Commit fe7026d

Browse files
committed
Merge branch 'next' of https://github.com/rubberduck-vba/Rubberduck into Issue1974
2 parents 1c00cc8 + 2347142 commit fe7026d

15 files changed

+157
-154
lines changed

RetailCoder.VBE/App.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ public void Startup()
141141
_hooks.HookHotkeys(); // need to hook hotkeys before we localize menus, to correctly display ShortcutTexts
142142
_appMenus.Localize();
143143
UpdateLoggingLevel();
144+
145+
if (_vbe.VBProjects.Count != 0)
146+
{
147+
_parser.State.OnParseRequested(this);
148+
}
144149
}
145150

146151
public void Shutdown()

RetailCoder.VBE/Inspections/ImplicitByRefParameterInspection.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@ public ImplicitByRefParameterInspection(RubberduckParserState state)
2121

2222
public override IEnumerable<InspectionResultBase> GetInspectionResults()
2323
{
24-
var interfaceMembers = UserDeclarations.FindInterfaceImplementationMembers();
24+
var interfaceMembersScope = UserDeclarations.FindInterfaceImplementationMembers().Select(m => m.Scope);
25+
var builtinEventHandlers = State.AllDeclarations.FindBuiltInEventHandlers();
2526

2627
var issues = (from item in UserDeclarations
2728
where
2829
!item.IsInspectionDisabled(AnnotationName)
2930
&& item.DeclarationType == DeclarationType.Parameter
3031
// ParamArray parameters do not allow an explicit "ByRef" parameter mechanism.
3132
&& !((ParameterDeclaration)item).IsParamArray
32-
&& !interfaceMembers.Select(m => m.Scope).Contains(item.ParentScope)
33-
&& !State.AllDeclarations.FindBuiltInEventHandlers().Contains(item.ParentDeclaration)
33+
&& !interfaceMembersScope.Contains(item.ParentScope)
34+
&& !builtinEventHandlers.Contains(item.ParentDeclaration)
3435
let arg = item.Context as VBAParser.ArgContext
3536
where arg != null && arg.BYREF() == null && arg.BYVAL() == null
3637
select new QualifiedContext<VBAParser.ArgContext>(item.QualifiedName, arg))

RetailCoder.VBE/Inspections/InspectionResultBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public int CompareTo(object obj)
121121
public object[] ToArray()
122122
{
123123
var module = QualifiedSelection.QualifiedName;
124-
return new object[] { Inspection.Severity.ToString(), module.ProjectTitle, module.ComponentTitle, Description, QualifiedSelection.Selection.StartLine, QualifiedSelection.Selection.StartColumn };
124+
return new object[] { Inspection.Severity.ToString(), module.ProjectTitle, module.ComponentName, Description, QualifiedSelection.Selection.StartLine, QualifiedSelection.Selection.StartColumn };
125125
}
126126

127127
public string ToCsvString()

RetailCoder.VBE/Inspections/SelfAssignedDeclarationInspection.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
3939
&& declaration.IsTypeSpecified
4040
&& !ValueTypes.Contains(declaration.AsTypeName)
4141
&& declaration.DeclarationType == DeclarationType.Variable
42-
&& declaration.AsTypeDeclaration.DeclarationType != DeclarationType.UserDefinedType
42+
&& (declaration.AsTypeDeclaration == null
43+
|| declaration.AsTypeDeclaration.DeclarationType != DeclarationType.UserDefinedType)
4344
&& declaration.ParentScopeDeclaration != null
4445
&& declaration.ParentScopeDeclaration.DeclarationType.HasFlag(DeclarationType.Member))
4546
.Select(issue => new SelfAssignedDeclarationInspectionResult(this, issue));

RetailCoder.VBE/Inspections/VariableTypeNotDeclaredInspectionResult.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Linq;
23
using Antlr4.Runtime;
34
using Rubberduck.Parsing.Grammar;
45
using Rubberduck.Parsing.Symbols;
@@ -90,7 +91,25 @@ private string DeclareExplicitVariant(VBAParser.ArgContext context, out string i
9091
}
9192

9293
instruction = context.GetText();
93-
return instruction + ' ' + Tokens.As + ' ' + Tokens.Variant;
94+
if (!context.children.Select(s => s.GetType()).Contains(typeof(VBAParser.ArgDefaultValueContext)))
95+
{
96+
return instruction + ' ' + Tokens.As + ' ' + Tokens.Variant;
97+
}
98+
99+
var fix = string.Empty;
100+
var hasArgDefaultValue = false;
101+
foreach (var child in context.children)
102+
{
103+
if (child.GetType() == typeof(VBAParser.ArgDefaultValueContext))
104+
{
105+
fix += Tokens.As + ' ' + Tokens.Variant + ' ';
106+
hasArgDefaultValue = true;
107+
}
108+
109+
fix += child.GetText();
110+
}
111+
112+
return hasArgDefaultValue ? fix : fix + ' ' + Tokens.As + ' ' + Tokens.Variant;
94113
}
95114

96115
private string DeclareExplicitVariant(VBAParser.ConstSubStmtContext context, out string instruction)

RetailCoder.VBE/UI/Command/AddTestMethodCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ protected override bool CanExecuteImpl(object parameter)
3434
d.DeclarationType == DeclarationType.ProceduralModule &&
3535
d.Annotations.Any(a => a.AnnotationType == AnnotationType.TestModule));
3636

37-
return testModules.Any(a => a.QualifiedName.QualifiedModuleName.Component == _vbe.SelectedVBComponent);
37+
// the code modules consistently match correctly, but the components don't
38+
return testModules.Any(a => a.QualifiedName.QualifiedModuleName.Component.CodeModule == _vbe.SelectedVBComponent.CodeModule);
3839
}
3940

4041
protected override void ExecuteImpl(object parameter)

RetailCoder.VBE/UI/Command/AddTestMethodExpectedErrorCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ protected override bool CanExecuteImpl(object parameter)
3434
d.DeclarationType == DeclarationType.ProceduralModule &&
3535
d.Annotations.Any(a => a.AnnotationType == AnnotationType.TestModule));
3636

37-
return testModules.Any(a => a.QualifiedName.QualifiedModuleName.Component == _vbe.SelectedVBComponent);
37+
// the code modules consistently match correctly, but the components don't
38+
return testModules.Any(a => a.QualifiedName.QualifiedModuleName.Component.CodeModule == _vbe.SelectedVBComponent.CodeModule);
3839
}
3940

4041
protected override void ExecuteImpl(object parameter)

RetailCoder.VBE/UI/Command/MenuItems/RubberduckCommandBar.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void SetSelectionText(Declaration declaration)
5151
if (selection.HasValue) { SetSelectionText(selection.Value); }
5252
_selectionButton.TooltipText = _selectionButton.Caption;
5353
}
54-
else if (declaration != null)
54+
else if (declaration != null && !declaration.IsBuiltIn && declaration.DeclarationType != DeclarationType.ClassModule && declaration.DeclarationType != DeclarationType.ProceduralModule)
5555
{
5656
var typeName = declaration.HasTypeHint
5757
? Declaration.TypeHintToTypeName[declaration.TypeHint]
@@ -63,6 +63,28 @@ public void SetSelectionText(Declaration declaration)
6363
declaration.IdentifierName,
6464
RubberduckUI.ResourceManager.GetString("DeclarationType_" + declaration.DeclarationType, UI.Settings.Settings.Culture),
6565
string.IsNullOrEmpty(declaration.AsTypeName) ? string.Empty : ": " + typeName);
66+
67+
_selectionButton.TooltipText = string.IsNullOrEmpty(declaration.DescriptionString)
68+
? _selectionButton.Caption
69+
: declaration.DescriptionString;
70+
}
71+
else if (declaration != null)
72+
{
73+
// todo: confirm this is what we want, and then refator
74+
var selection = _vbe.ActiveCodePane.GetQualifiedSelection();
75+
if (selection.HasValue)
76+
{
77+
var typeName = declaration.HasTypeHint
78+
? Declaration.TypeHintToTypeName[declaration.TypeHint]
79+
: declaration.AsTypeName;
80+
81+
_selectionButton.Caption = string.Format("{0}|{1}: {2} ({3}{4})",
82+
selection.Value.Selection,
83+
declaration.QualifiedName.QualifiedModuleName,
84+
declaration.IdentifierName,
85+
RubberduckUI.ResourceManager.GetString("DeclarationType_" + declaration.DeclarationType, UI.Settings.Settings.Culture),
86+
string.IsNullOrEmpty(declaration.AsTypeName) ? string.Empty : ": " + typeName);
87+
}
6688
_selectionButton.TooltipText = string.IsNullOrEmpty(declaration.DescriptionString)
6789
? _selectionButton.Caption
6890
: declaration.DescriptionString;

RetailCoder.VBE/UI/Inspections/InspectionResultsViewModel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
4+
using System.Diagnostics;
45
using System.Globalization;
56
using System.IO;
67
using System.Linq;
@@ -260,6 +261,7 @@ private void _state_StateChanged(object sender, EventArgs e)
260261

261262
private async void RefreshInspections()
262263
{
264+
var stopwatch = Stopwatch.StartNew();
263265
IsBusy = true;
264266

265267
var results = (await _inspector.FindIssuesAsync(_state, CancellationToken.None)).ToList();
@@ -289,6 +291,9 @@ private async void RefreshInspections()
289291
IsBusy = false;
290292
SelectedItem = null;
291293
});
294+
295+
stopwatch.Stop();
296+
LogManager.GetCurrentClassLogger().Trace("Inspections loaded in {0}ms", stopwatch.ElapsedMilliseconds);
292297
}
293298

294299
private void ExecuteQuickFixes(IEnumerable<CodeInspectionQuickFix> quickFixes)

RetailCoder.VBE/UnitTesting/NewTestMethodCommand.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Runtime.InteropServices;
33
using Microsoft.Vbe.Interop;
44
using Rubberduck.Parsing.Annotations;
5+
using Rubberduck.Parsing.Symbols;
56
using Rubberduck.Parsing.VBA;
67
using Rubberduck.UI;
78

@@ -67,11 +68,12 @@ public void NewTestMethod()
6768

6869
try
6970
{
70-
var declaration = _state.AllUserDeclarations.First(f =>
71-
f.DeclarationType == Parsing.Symbols.DeclarationType.ProceduralModule &&
71+
var declaration = _state.AllUserDeclarations.FirstOrDefault(f =>
7272
f.QualifiedName.QualifiedModuleName.Component.CodeModule == _vbe.ActiveCodePane.CodeModule);
7373

74-
if (declaration.Annotations.Any(a => a.AnnotationType == AnnotationType.TestModule))
74+
if (declaration != null &&
75+
declaration.DeclarationType == DeclarationType.ProceduralModule &&
76+
declaration.Annotations.Any(a => a.AnnotationType == AnnotationType.TestModule))
7577
{
7678
var module = _vbe.ActiveCodePane.CodeModule;
7779
var name = GetNextTestMethodName(module.Parent);
@@ -95,11 +97,12 @@ public void NewExpectedErrorTestMethod()
9597

9698
try
9799
{
98-
var declaration = _state.AllUserDeclarations.First(f =>
99-
f.DeclarationType == Parsing.Symbols.DeclarationType.ProceduralModule &&
100+
var declaration = _state.AllUserDeclarations.FirstOrDefault(f =>
100101
f.QualifiedName.QualifiedModuleName.Component.CodeModule == _vbe.ActiveCodePane.CodeModule);
101102

102-
if (declaration.Annotations.Any(a => a.AnnotationType == AnnotationType.TestModule))
103+
if (declaration != null &&
104+
declaration.DeclarationType == DeclarationType.ProceduralModule &&
105+
declaration.Annotations.Any(a => a.AnnotationType == AnnotationType.TestModule))
103106
{
104107
var module = _vbe.ActiveCodePane.CodeModule;
105108
var name = GetNextTestMethodName(module.Parent);

0 commit comments

Comments
 (0)