Skip to content

Commit cb8e229

Browse files
committed
Merge pull request #97 from rubberduck-vba/next
sync with main repo
2 parents 573339d + 0426312 commit cb8e229

23 files changed

+438
-124
lines changed

RetailCoder.VBE/Inspections/ObsoleteTypeHintInspection.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,18 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
2222

2323
var declarations = from item in results
2424
where item.HasTypeHint()
25-
// bug: this inspection result only has one value. Why are we passing two in?
26-
select new ObsoleteTypeHintInspectionResult(this, string.Format(InspectionsUI.ObsoleteTypeHintInspectionResultFormat, InspectionsUI.Inspections_Declaration, item.DeclarationType.ToString().ToLower(), item.IdentifierName), new QualifiedContext(item.QualifiedName, item.Context), item);
27-
// todo: localize this InspectionResultFormat properly
25+
select new ObsoleteTypeHintInspectionResult(this,
26+
string.Format(InspectionsUI.ObsoleteTypeHintInspectionResultFormat,
27+
InspectionsUI.Inspections_Declaration, item.DeclarationType.ToString().ToLower(),
28+
item.IdentifierName), new QualifiedContext(item.QualifiedName, item.Context), item);
29+
2830
var references = from item in results.SelectMany(d => d.References)
2931
where item.HasTypeHint()
30-
select new ObsoleteTypeHintInspectionResult(this, string.Format(InspectionsUI.ObsoleteTypeHintInspectionResultFormat, InspectionsUI.Inspections_Usage, item.Declaration.DeclarationType.ToString().ToLower(), item.IdentifierName), new QualifiedContext(item.QualifiedModuleName, item.Context), item.Declaration);
32+
select new ObsoleteTypeHintInspectionResult(this,
33+
string.Format(InspectionsUI.ObsoleteTypeHintInspectionResultFormat,
34+
InspectionsUI.Inspections_Usage, item.Declaration.DeclarationType.ToString().ToLower(),
35+
item.IdentifierName), new QualifiedContext(item.QualifiedModuleName, item.Context),
36+
item.Declaration);
3137

3238
return declarations.Union(references);
3339
}

RetailCoder.VBE/Inspections/UntypedFunctionUsageInspectionResult.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,20 @@ public override string Description
3232
public class UntypedFunctionUsageQuickFix : CodeInspectionQuickFix
3333
{
3434
public UntypedFunctionUsageQuickFix(ParserRuleContext context, QualifiedSelection selection)
35-
: base(context, selection, string.Format(InspectionsUI.QuickFixUseTypedFunction_, context.GetText(), context.GetText() + "$"))
35+
: base(context, selection,
36+
string.Format(InspectionsUI.QuickFixUseTypedFunction_,
37+
context.GetText(), context.GetText().Insert(context.GetText().IndexOf('('), "$")))
3638
{
3739
}
3840

3941
public override void Fix()
4042
{
4143
var originalInstruction = Context.GetText();
42-
var newInstruction = originalInstruction + "$";
44+
var newInstruction = originalInstruction.Insert(originalInstruction.IndexOf('('), "$");
4345
var selection = Selection.Selection;
4446

4547
var module = Selection.QualifiedName.Component.CodeModule;
46-
var lines = module.get_Lines(selection.StartLine, selection.LineCount);
48+
var lines = module.Lines[selection.StartLine, selection.LineCount];
4749

4850
var result = lines.Replace(originalInstruction, newInstruction);
4951
module.ReplaceLine(selection.StartLine, result);

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerComponentViewModel.cs

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,53 @@ public CodeExplorerComponentViewModel(CodeExplorerItemViewModel parent, Declarat
4747
.OrderBy(item => item.QualifiedSelection.Selection.StartLine)
4848
.Select(item => new CodeExplorerMemberViewModel(this, item, grouping)))
4949
.ToList<CodeExplorerItemViewModel>();
50-
50+
51+
_name = _declaration.IdentifierName;
52+
53+
var component = declaration.QualifiedName.QualifiedModuleName.Component;
54+
if (component.Type == vbext_ComponentType.vbext_ct_Document)
55+
{
56+
try
57+
{
58+
var parenthesizedName = component.Properties.Item("Name").Value.ToString();
59+
60+
if (ContainsBuiltinDocumentPropertiesProperty())
61+
{
62+
CodeExplorerItemViewModel node = this;
63+
while (node.Parent != null)
64+
{
65+
node = node.Parent;
66+
}
67+
68+
((CodeExplorerProjectViewModel) node).SetParenthesizedName(parenthesizedName);
69+
}
70+
else
71+
{
72+
_name += " (" + parenthesizedName + ")";
73+
}
74+
}
75+
catch
76+
{
77+
// gotcha! (this means that the property either doesn't exist or we weren't able to get it for some reason)
78+
}
79+
}
80+
}
81+
82+
private bool ContainsBuiltinDocumentPropertiesProperty()
83+
{
84+
var component = _declaration.QualifiedName.QualifiedModuleName.Component;
85+
86+
try
87+
{
88+
component.Properties.Item("BuiltinDocumentProperties");
89+
}
90+
catch
91+
{
92+
// gotcha! (this means that the property either doesn't exist or we weren't able to get it for some reason)
93+
return false;
94+
}
95+
96+
return true;
5197
}
5298

5399
private bool _isErrorState;
@@ -62,8 +108,9 @@ public bool IsTestModule
62108
}
63109
}
64110

65-
public override string Name { get { return _declaration.IdentifierName; } }
66-
public override string NameWithSignature { get { return Name; } }
111+
private readonly string _name;
112+
public override string Name { get { return _name; } }
113+
public override string NameWithSignature { get { return _name; } }
67114

68115
public override QualifiedSelection? QualifiedSelection { get { return _declaration.QualifiedSelection; } }
69116

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerProjectViewModel.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class CodeExplorerProjectViewModel : CodeExplorerItemViewModel, ICodeExpl
2727
public CodeExplorerProjectViewModel(FolderHelper folderHelper, Declaration declaration, IEnumerable<Declaration> declarations)
2828
{
2929
_declaration = declaration;
30+
_name = _declaration.IdentifierName;
3031
IsExpanded = true;
3132
_folderTree = folderHelper.GetFolderTree(declaration);
3233

@@ -43,11 +44,6 @@ public CodeExplorerProjectViewModel(FolderHelper folderHelper, Declaration decla
4344
{
4445
Console.WriteLine(e);
4546
}
46-
47-
foreach (var folder in _folderTree.Items.OfType<CodeExplorerCustomFolderViewModel>())
48-
{
49-
folder.SetParent(this);
50-
}
5147
}
5248

5349
private void FillFolders(IEnumerable<Declaration> declarations)
@@ -72,6 +68,11 @@ private bool AddNodesToTree(CodeExplorerCustomFolderViewModel tree, List<Declara
7268
continue;
7369
}
7470

71+
if (folder.Parent.Name == string.Empty)
72+
{
73+
folder.SetParent(this);
74+
}
75+
7576
var parents = grouping.Where(
7677
item => ComponentTypes.Contains(item.DeclarationType) &&
7778
item.CustomFolder.Replace("\"", string.Empty) == folder.FullPath)
@@ -94,8 +95,14 @@ private bool AddNodesToTree(CodeExplorerCustomFolderViewModel tree, List<Declara
9495
// projects are always at the top of the tree
9596
public override CodeExplorerItemViewModel Parent { get { return null; } }
9697

97-
public override string Name { get { return _declaration.IdentifierName; } }
98-
public override string NameWithSignature { get { return Name; } }
98+
private string _name;
99+
public override string Name { get { return _name; } }
100+
public override string NameWithSignature { get { return _name; } }
99101
public override QualifiedSelection? QualifiedSelection { get { return _declaration.QualifiedSelection; } }
102+
103+
public void SetParenthesizedName(string parenthesizedName)
104+
{
105+
_name += " (" + parenthesizedName + ")";
106+
}
100107
}
101108
}

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using System.Windows.Input;
66
using System.Windows.Threading;
7+
using Microsoft.Vbe.Interop;
78
using Rubberduck.Navigation.Folders;
89
using Rubberduck.Parsing.Symbols;
910
using Rubberduck.Parsing.VBA;
@@ -218,7 +219,7 @@ private void ParserState_StateChanged(object sender, EventArgs e)
218219
{
219220
return;
220221
}
221-
222+
222223
var userDeclarations = _state.AllUserDeclarations
223224
.GroupBy(declaration => declaration.Project)
224225
.Where(grouping => grouping.Key != null)
@@ -230,6 +231,9 @@ private void ParserState_StateChanged(object sender, EventArgs e)
230231
return;
231232
}
232233

234+
235+
var components = userDeclarations.SelectMany(s => s.Key.VBComponents.Cast<VBComponent>()).FirstOrDefault(s => s.Name == "asdf");
236+
233237
var newProjects = userDeclarations.Select(grouping =>
234238
new CodeExplorerProjectViewModel(_folderHelper,
235239
grouping.SingleOrDefault(declaration => declaration.DeclarationType == DeclarationType.Project),

RetailCoder.VBE/UI/Command/AddTestMethodCommand.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
using System.Linq;
12
using System.Runtime.InteropServices;
2-
using Rubberduck.UI.UnitTesting;
3+
using Microsoft.Vbe.Interop;
4+
using Rubberduck.Parsing.Annotations;
5+
using Rubberduck.Parsing.Symbols;
6+
using Rubberduck.Parsing.VBA;
37
using Rubberduck.UnitTesting;
48

59
namespace Rubberduck.UI.Command
@@ -10,11 +14,26 @@ namespace Rubberduck.UI.Command
1014
[ComVisible(false)]
1115
public class AddTestMethodCommand : CommandBase
1216
{
17+
private readonly VBE _vbe;
1318
private readonly NewTestMethodCommand _command;
19+
private readonly RubberduckParserState _state;
1420

15-
public AddTestMethodCommand(NewTestMethodCommand command)
21+
public AddTestMethodCommand(VBE vbe, RubberduckParserState state, NewTestMethodCommand command)
1622
{
23+
_vbe = vbe;
1724
_command = command;
25+
_state = state;
26+
}
27+
28+
public override bool CanExecute(object parameter)
29+
{
30+
if (_state.Status != ParserState.Ready) { return false; }
31+
32+
var testModules = _state.AllUserDeclarations.Where(d =>
33+
d.DeclarationType == DeclarationType.ProceduralModule &&
34+
d.Annotations.Any(a => a.AnnotationType == AnnotationType.TestModule));
35+
36+
return testModules.Any(a => a.QualifiedName.QualifiedModuleName.Component == _vbe.SelectedVBComponent);
1837
}
1938

2039
public override void Execute(object parameter)

RetailCoder.VBE/UI/Command/AddTestMethodExpectedErrorCommand.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
using System.Linq;
12
using System.Runtime.InteropServices;
3+
using Microsoft.Vbe.Interop;
4+
using Rubberduck.Parsing.Annotations;
5+
using Rubberduck.Parsing.Symbols;
6+
using Rubberduck.Parsing.VBA;
27
using Rubberduck.UnitTesting;
38

49
namespace Rubberduck.UI.Command
@@ -9,11 +14,26 @@ namespace Rubberduck.UI.Command
914
[ComVisible(false)]
1015
public class AddTestMethodExpectedErrorCommand : CommandBase
1116
{
17+
private readonly VBE _vbe;
1218
private readonly NewTestMethodCommand _command;
19+
private readonly RubberduckParserState _state;
1320

14-
public AddTestMethodExpectedErrorCommand(NewTestMethodCommand command)
21+
public AddTestMethodExpectedErrorCommand(VBE vbe, RubberduckParserState state, NewTestMethodCommand command)
1522
{
23+
_vbe = vbe;
1624
_command = command;
25+
_state = state;
26+
}
27+
28+
public override bool CanExecute(object parameter)
29+
{
30+
if (_state.Status != ParserState.Ready) { return false; }
31+
32+
var testModules = _state.AllUserDeclarations.Where(d =>
33+
d.DeclarationType == DeclarationType.ProceduralModule &&
34+
d.Annotations.Any(a => a.AnnotationType == AnnotationType.TestModule));
35+
36+
return testModules.Any(a => a.QualifiedName.QualifiedModuleName.Component == _vbe.SelectedVBComponent);
1737
}
1838

1939
public override void Execute(object parameter)

RetailCoder.VBE/UI/Command/AddTestModuleCommand.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Runtime.InteropServices;
22
using Microsoft.Vbe.Interop;
3+
using Rubberduck.Parsing.VBA;
34
using Rubberduck.UnitTesting;
45
using Rubberduck.VBEditor.Extensions;
56

@@ -12,26 +13,26 @@ namespace Rubberduck.UI.Command
1213
public class AddTestModuleCommand : CommandBase
1314
{
1415
private readonly VBE _vbe;
16+
private readonly RubberduckParserState _state;
1517
private readonly NewUnitTestModuleCommand _command;
1618

17-
public AddTestModuleCommand(VBE vbe, NewUnitTestModuleCommand command)
19+
public AddTestModuleCommand(VBE vbe, RubberduckParserState state, NewUnitTestModuleCommand command)
1820
{
1921
_vbe = vbe;
22+
_state = state;
2023
_command = command;
2124
}
2225

2326
public override bool CanExecute(object parameter)
2427
{
2528
var app = _vbe.HostApplication();
26-
if (app == null)
29+
if (app == null || _state.Status != ParserState.Ready)
2730
{
2831
return false;
2932
}
30-
else
31-
{
32-
// Outlook requires test methods to be located in [ThisOutlookSession] class.
33-
return app.ApplicationName != "Outlook";
34-
}
33+
34+
// Outlook requires test methods to be located in [ThisOutlookSession] class.
35+
return app.ApplicationName != "Outlook";
3536
}
3637

3738
public override void Execute(object parameter)

RetailCoder.VBE/UI/Command/RunAllTestsCommand.cs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System;
2+
using System.Diagnostics;
13
using Rubberduck.Parsing.VBA;
24
using Rubberduck.UI.UnitTesting;
35
using Rubberduck.UnitTesting;
@@ -12,8 +14,8 @@ public class RunAllTestsCommand : CommandBase
1214
private readonly ITestEngine _engine;
1315
private readonly TestExplorerModel _model;
1416
private readonly RubberduckParserState _state;
15-
16-
public RunAllTestsCommand(ITestEngine engine, TestExplorerModel model, RubberduckParserState state)
17+
18+
public RunAllTestsCommand(RubberduckParserState state, ITestEngine engine, TestExplorerModel model)
1719
{
1820
_engine = engine;
1921
_model = model;
@@ -31,11 +33,39 @@ private void StateChanged(object sender, ParserStateEventArgs e)
3133
{
3234
if (e.State != ParserState.Ready) { return; }
3335

36+
var stopwatch = new Stopwatch();
37+
3438
_model.ClearLastRun();
3539
_model.IsBusy = true;
40+
41+
stopwatch.Start();
3642
_engine.Run(_model.Tests);
43+
stopwatch.Stop();
44+
3745
_model.IsBusy = false;
3846
_state.StateChanged -= StateChanged;
47+
48+
OnRunCompleted(new TestRunEventArgs(stopwatch.ElapsedMilliseconds));
49+
}
50+
51+
public event EventHandler<TestRunEventArgs> RunCompleted;
52+
protected virtual void OnRunCompleted(TestRunEventArgs e)
53+
{
54+
var handler = RunCompleted;
55+
if (handler != null)
56+
{
57+
handler.Invoke(this, e);
58+
}
59+
}
60+
}
61+
62+
public struct TestRunEventArgs
63+
{
64+
public long Duration { get; private set; }
65+
66+
public TestRunEventArgs(long duration)
67+
{
68+
Duration = duration;
3969
}
4070
}
4171
}

RetailCoder.VBE/UI/RubberduckUI.Designer.cs

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

0 commit comments

Comments
 (0)