Skip to content

Commit 83c4c5d

Browse files
authored
Merge branch 'next' into Issue1434
2 parents 381918b + af8bf50 commit 83c4c5d

19 files changed

+1066
-1002
lines changed

RetailCoder.VBE/Inspections/UnassignedVariableUsageInspection.cs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System.Collections.Generic;
22
using System.Linq;
3+
using Antlr4.Runtime;
4+
using Rubberduck.Parsing;
35
using Rubberduck.Parsing.Symbols;
46
using Rubberduck.Parsing.VBA;
57

@@ -27,10 +29,46 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
2729
.SelectMany(declaration => declaration.References)
2830
.Where(usage => !usage.IsInspectionDisabled(AnnotationName));
2931

32+
var lenFunction = BuiltInDeclarations.SingleOrDefault(s => s.Scope == "VBE7.DLL;VBA.Strings.Len");
33+
var lenbFunction = BuiltInDeclarations.SingleOrDefault(s => s.Scope == "VBE7.DLL;VBA.Strings.LenB");
34+
3035
foreach (var issue in usages)
3136
{
32-
yield return new UnassignedVariableUsageInspectionResult(this, issue.Context, issue.QualifiedModuleName, issue.Declaration);
37+
if (DeclarationReferencesContainsReference(lenFunction, issue) ||
38+
DeclarationReferencesContainsReference(lenbFunction, issue))
39+
{
40+
continue;
41+
}
42+
43+
yield return
44+
new UnassignedVariableUsageInspectionResult(this, issue.Context, issue.QualifiedModuleName,
45+
issue.Declaration);
46+
}
47+
}
48+
49+
private bool DeclarationReferencesContainsReference(Declaration parentDeclaration, IdentifierReference issue)
50+
{
51+
if (parentDeclaration == null)
52+
{
53+
return false;
54+
}
55+
56+
var lenUsesIssue = false;
57+
foreach (var reference in parentDeclaration.References)
58+
{
59+
var context = (ParserRuleContext) reference.Context.Parent;
60+
if (context.GetSelection().Contains(issue.Selection))
61+
{
62+
lenUsesIssue = true;
63+
break;
64+
}
65+
}
66+
67+
if (lenUsesIssue)
68+
{
69+
return true;
3370
}
71+
return false;
3472
}
3573
}
3674
}

RetailCoder.VBE/NLog.dll.nlog

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
<target
77
xsi:type="File"
88
name="file"
9-
fileName="${specialfolder:folder=ApplicationData}/Rubberduck/logs/rubberduck.log"
9+
fileName="${specialfolder:folder=ApplicationData}/Rubberduck/Logs/RubberduckLog.txt"
1010
layout="${longdate};${uppercase:${level}};${logger};${message};${exception:format=tostring}"
11-
archiveFileName="${specialfolder:folder=ApplicationData}/Rubberduck/logs/archives/rubberduck.{#}.log"
11+
archiveFileName="${specialfolder:folder=ApplicationData}/Rubberduck/Logs/archives/RubberduckLog.{#}.txt"
1212
archiveAboveSize="5242880"
1313
archiveNumbering="Sequence"
1414
concurrentWrites="true"

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ public ObservableCollection<CodeExplorerItemViewModel> Projects
228228
get { return _projects; }
229229
set
230230
{
231+
ReorderChildNodes(value);
231232
_projects = new ObservableCollection<CodeExplorerItemViewModel>(value.OrderBy(o => o.NameWithSignature));
232-
233-
ReorderChildNodes(_projects);
233+
234234
OnPropertyChanged();
235235
}
236236
}

RetailCoder.VBE/Refactorings/MoveCloserToUsage/MoveCloserToUsageRefactoring.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ private void MoveCloserToUsage()
110110

111111
private void _state_StateChanged(object sender, ParserStateEventArgs e)
112112
{
113-
if (e.State != ParserState.ResolvedDeclarations) { return; }
113+
if (e.State != ParserState.Ready) { return; }
114114

115115
var newTarget = _state.AllUserDeclarations.FirstOrDefault(
116116
item => item.ComponentName == _target.ComponentName &&
@@ -121,7 +121,7 @@ private void _state_StateChanged(object sender, ParserStateEventArgs e)
121121

122122
if (newTarget != null)
123123
{
124-
UpdateCallsToOtherModule(newTarget.References);
124+
UpdateCallsToOtherModule(newTarget.References.ToList());
125125
RemoveField(newTarget);
126126
}
127127

@@ -273,20 +273,28 @@ private string RemoveExtraComma(string str, int numParams, int indexRemoved)
273273
return str.Remove(str.NthIndexOf(',', commaToRemove), 1);
274274
}
275275

276-
private void UpdateCallsToOtherModule(IEnumerable<IdentifierReference> references)
276+
private void UpdateCallsToOtherModule(List<IdentifierReference> references)
277277
{
278-
var identifierReferences = references.ToList();
278+
if (!references.Any())
279+
{
280+
return;
281+
}
279282

280-
var module = identifierReferences[0].QualifiedModuleName.Component.CodeModule;
283+
var module = references[0].QualifiedModuleName.Component.CodeModule;
281284

282-
foreach (var reference in identifierReferences.OrderByDescending(o => o.Selection.StartLine).ThenByDescending(t => t.Selection.StartColumn))
285+
foreach (var reference in references.OrderByDescending(o => o.Selection.StartLine).ThenByDescending(t => t.Selection.StartColumn))
283286
{
284287
var parent = reference.Context.Parent;
285-
while (!(parent is VBAParser.MemberAccessExprContext))
288+
while (!(parent is VBAParser.MemberAccessExprContext) && parent.Parent != null)
286289
{
287290
parent = parent.Parent;
288291
}
289292

293+
if (!(parent is VBAParser.MemberAccessExprContext))
294+
{
295+
continue;
296+
}
297+
290298
var parentSelection = ((VBAParser.MemberAccessExprContext)parent).GetSelection();
291299

292300
var oldText = module.Lines[parentSelection.StartLine, parentSelection.LineCount];

RetailCoder.VBE/UI/RegexAssistant/RegexAssistant.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
<TextBox HorizontalAlignment="Stretch"
7171
VerticalAlignment="Top" Height="23"
7272
VerticalContentAlignment="Center" Margin="5"
73-
Text="{Binding Pattern}"/>
73+
Text="{Binding Pattern, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
7474

7575
<StackPanel Orientation="Horizontal" Margin="5,0,5,0">
7676
<CheckBox Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=RegexAssistant_GlobalFlag}"

RetailCoder.VBE/UI/RubberduckUI.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RetailCoder.VBE/UI/RubberduckUI.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1716,7 +1716,7 @@ All our stargazers, likers &amp; followers, for the warm fuzzies
17161716
<value>Publish Existing Repository</value>
17171717
</data>
17181718
<data name="RubberduckFatalError" xml:space="preserve">
1719-
<value>Rubberduck encountered an error. Please save your work and restart the host program, then upload your log file to our GitHub page.</value>
1719+
<value>Rubberduck encountered an error. Please save your work and restart the host program, then upload your log file located at "C:\Users\{username}\AppData\Roaming\Rubberduck\Logs\RubberduckLog.txt" to a GitHub issue at "https://github.com/rubberduck-vba/Rubberduck/issues/new".</value>
17201720
</data>
17211721
<data name="TestExplorerMenu_AddExpectedErrorTestMethod" xml:space="preserve">
17221722
<value>Test Method (&amp;Expected Error)</value>

Rubberduck.Parsing/VBA/RubberduckParser.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,20 @@ private readonly IDictionary<VBComponent, IDictionary<Tuple<string, DeclarationT
3232
private readonly IEnumerable<ICustomDeclarationLoader> _customDeclarationLoaders;
3333
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
3434

35+
private readonly bool _isTestScope;
36+
3537
public RubberduckParser(
3638
RubberduckParserState state,
3739
IAttributeParser attributeParser,
3840
Func<IVBAPreprocessor> preprocessorFactory,
39-
IEnumerable<ICustomDeclarationLoader> customDeclarationLoaders)
41+
IEnumerable<ICustomDeclarationLoader> customDeclarationLoaders,
42+
bool isTestScope = false)
4043
{
4144
_state = state;
4245
_attributeParser = attributeParser;
4346
_preprocessorFactory = preprocessorFactory;
4447
_customDeclarationLoaders = customDeclarationLoaders;
48+
_isTestScope = isTestScope;
4549

4650
state.ParseRequest += ReparseRequested;
4751
}
@@ -53,8 +57,15 @@ public RubberduckParser(
5357

5458
private void ReparseRequested(object sender, EventArgs e)
5559
{
56-
Cancel();
57-
Task.Run(() => ParseAll(_cancellationTokens[0]));
60+
if (!_isTestScope)
61+
{
62+
Cancel();
63+
Task.Run(() => ParseAll(_cancellationTokens[0]));
64+
}
65+
else
66+
{
67+
Parse(_cancellationTokens[0]);
68+
}
5869
}
5970

6071
/// <summary>

RubberduckTests/Inspections/MoveFieldCloserToUsageInspectionTests.cs

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -277,43 +277,43 @@ Public Sub Foo()
277277
Assert.AreEqual(expectedCode, module.Lines());
278278
}
279279

280-
// [TestMethod]
281-
// [TestCategory("Inspections")]
282-
// public void MoveFieldCloserToUsage_QuickFixWorks()
283-
// {
284-
// const string inputCode =
285-
//@"Private bar As String
286-
//Public Sub Foo()
287-
// bar = ""test""
288-
//End Sub";
289-
290-
// const string expectedCode =
291-
//@"Public Sub Foo()
292-
293-
// Dim bar As String
294-
// bar = ""test""
295-
//End Sub";
296-
297-
// //Arrange
298-
// var builder = new MockVbeBuilder();
299-
// VBComponent component;
300-
// var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
301-
// var project = vbe.Object.VBProjects.Item(0);
302-
// var module = project.VBComponents.Item(0).CodeModule;
303-
// var mockHost = new Mock<IHostApplication>();
304-
// mockHost.SetupAllProperties();
305-
// var parser = MockParser.Create(vbe.Object, new RubberduckParserState());
306-
307-
// parser.Parse(new CancellationTokenSource());
308-
// if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
309-
310-
// var inspection = new MoveFieldCloserToUsageInspection(parser.State);
311-
// var inspectionResults = inspection.GetInspectionResults();
312-
313-
// inspectionResults.First().QuickFixes.First().Fix();
314-
315-
// Assert.AreEqual(expectedCode, module.Lines());
316-
// }
280+
[TestMethod]
281+
[TestCategory("Inspections")]
282+
public void MoveFieldCloserToUsage_QuickFixWorks()
283+
{
284+
const string inputCode =
285+
@"Private bar As String
286+
Public Sub Foo()
287+
bar = ""test""
288+
End Sub";
289+
290+
const string expectedCode =
291+
@"Public Sub Foo()
292+
293+
Dim bar As String
294+
bar = ""test""
295+
End Sub";
296+
297+
//Arrange
298+
var builder = new MockVbeBuilder();
299+
VBComponent component;
300+
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
301+
var project = vbe.Object.VBProjects.Item(0);
302+
var module = project.VBComponents.Item(0).CodeModule;
303+
var mockHost = new Mock<IHostApplication>();
304+
mockHost.SetupAllProperties();
305+
var parser = MockParser.Create(vbe.Object, new RubberduckParserState(vbe.Object, new Mock<ISinks>().Object));
306+
307+
parser.Parse(new CancellationTokenSource());
308+
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
309+
310+
var inspection = new MoveFieldCloserToUsageInspection(parser.State);
311+
var inspectionResults = inspection.GetInspectionResults();
312+
313+
inspectionResults.First().QuickFixes.First().Fix();
314+
315+
Assert.AreEqual(expectedCode, module.Lines());
316+
}
317317

318318
[TestMethod]
319319
[TestCategory("Inspections")]

RubberduckTests/MockParser.cs renamed to RubberduckTests/Mocks/MockParser.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
using Rubberduck.Parsing.Symbols;
77
using Rubberduck.Parsing.VBA;
88
using Rubberduck.VBEditor;
9-
using RubberduckTests.Mocks;
109
using Rubberduck.Parsing.Preprocessing;
1110
using System.Globalization;
1211
using System.Threading;
1312
using Rubberduck.Parsing;
1413

15-
namespace RubberduckTests
14+
namespace RubberduckTests.Mocks
1615
{
1716
public static class MockParser
1817
{
@@ -24,7 +23,7 @@ public static void ParseString(string inputCode, out QualifiedModuleName qualifi
2423
VBComponent component;
2524
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
2625
qualifiedModuleName = new QualifiedModuleName(component);
27-
var parser = MockParser.Create(vbe.Object, new RubberduckParserState(vbe.Object, new Mock<ISinks>().Object));
26+
var parser = Create(vbe.Object, new RubberduckParserState(vbe.Object, new Mock<ISinks>().Object));
2827

2928
parser.Parse(new CancellationTokenSource());
3029
if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); }
@@ -43,7 +42,7 @@ public static RubberduckParser Create(VBE vbe, RubberduckParserState state, IAtt
4342
{
4443
return new RubberduckParser(state, attributeParser,
4544
() => new VBAPreprocessor(double.Parse(vbe.Version, CultureInfo.InvariantCulture)),
46-
new List<ICustomDeclarationLoader> {new DebugDeclarations(state), new FormEventDeclarations(state), new AliasDeclarations(state)});
45+
new List<ICustomDeclarationLoader> {new DebugDeclarations(state), new FormEventDeclarations(state), new AliasDeclarations(state)}, true);
4746
}
4847
}
4948
}

RubberduckTests/Mocks/MockProjectBuilder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ private Mock<CodeModule> CreateCodeModuleMock(string content)
273273

274274
// ReSharper disable once UseIndexedProperty
275275
codeModule.Setup(m => m.get_Lines(It.IsAny<int>(), It.IsAny<int>()))
276-
.Returns<int, int>((start, count) => String.Join(Environment.NewLine, lines.Skip(start - 1).Take(count)));
276+
.Returns<int, int>((start, count) => string.Join(Environment.NewLine, lines.Skip(start - 1).Take(count)));
277277

278278
codeModule.Setup(m => m.ReplaceLine(It.IsAny<int>(), It.IsAny<string>()))
279279
.Callback<int, string>((index, str) => lines[index - 1] = str);
@@ -286,11 +286,11 @@ private Mock<CodeModule> CreateCodeModuleMock(string content)
286286
{
287287
if (index - 1 >= lines.Count)
288288
{
289-
lines.Add(newLine);
289+
lines.AddRange(newLine.Split(new[] {Environment.NewLine}, StringSplitOptions.None));
290290
}
291291
else
292292
{
293-
lines.Insert(index - 1, newLine);
293+
lines.InsertRange(index - 1, newLine.Split(new[] { Environment.NewLine }, StringSplitOptions.None));
294294
}
295295
});
296296

RubberduckTests/Refactoring/ExtractMethod/ExtractMethodExtractionTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Rubberduck.Refactorings.ExtractMethod;
88
using Rubberduck.VBEditor;
99
using Rubberduck.VBEditor.VBEInterfaces.RubberduckCodeModule;
10+
using RubberduckTests.Mocks;
1011

1112
namespace RubberduckTests.Refactoring.ExtractMethod
1213
{

RubberduckTests/Refactoring/ExtractMethod/ExtractMethodModelTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Rubberduck.Parsing.VBA;
99
using Rubberduck.Refactorings.ExtractMethod;
1010
using Rubberduck.VBEditor;
11+
using RubberduckTests.Mocks;
1112

1213
namespace RubberduckTests.Refactoring.ExtractMethod
1314
{

RubberduckTests/Refactoring/ExtractMethod/ExtractMethodParameterClassificationTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Rubberduck.Parsing.VBA;
1111
using Rubberduck.Refactorings.ExtractMethod;
1212
using Rubberduck.VBEditor;
13+
using RubberduckTests.Mocks;
1314

1415
namespace RubberduckTests.Refactoring.ExtractMethod
1516
{

RubberduckTests/Refactoring/ExtractMethod/ExtractMethodSelectionValidationTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Rubberduck.Parsing.VBA;
33
using Rubberduck.Refactorings.ExtractMethod;
44
using Rubberduck.VBEditor;
5+
using RubberduckTests.Mocks;
56

67
namespace RubberduckTests.Refactoring.ExtractMethod
78
{

RubberduckTests/Refactoring/ExtractMethod/ExtractMethodTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Rubberduck.Parsing.VBA;
66
using Rubberduck.Refactorings.ExtractMethod;
77
using Rubberduck.VBEditor;
8+
using RubberduckTests.Mocks;
89

910
namespace RubberduckTests.Refactoring.ExtractMethod
1011
{

RubberduckTests/Refactoring/ExtractMethod/ExtractedMethodRefactoringTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Rubberduck.Refactorings.ExtractMethod;
77
using Rubberduck.VBEditor;
88
using Rubberduck.VBEditor.VBEInterfaces.RubberduckCodeModule;
9+
using RubberduckTests.Mocks;
910

1011
namespace RubberduckTests.Refactoring.ExtractMethod
1112
{

0 commit comments

Comments
 (0)