Skip to content

Commit 9788cc3

Browse files
committed
Merge branch 'Issue1681' of https://github.com/Hosch250/Rubberduck
2 parents b50294a + e7fff50 commit 9788cc3

File tree

6 files changed

+56
-16
lines changed

6 files changed

+56
-16
lines changed

RetailCoder.VBE/Inspections/VariableTypeNotDeclaredInspectionResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public override void Fix()
6666
return;
6767
}
6868

69-
var fixedCodeLine = codeLine.Replace(originalInstruction, fix);
69+
var fixedCodeLine = codeLine.Remove(Context.Start.Column, originalInstruction.Length).Insert(Context.Start.Column, fix);
7070
codeModule.ReplaceLine(Selection.Selection.StartLine, fixedCodeLine);
7171
}
7272

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerItemViewModel.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using System.Linq;
33
using System.Windows.Media.Imaging;
4+
using Microsoft.Vbe.Interop;
45
using Rubberduck.Parsing.Symbols;
56
using Rubberduck.UI;
67
using Rubberduck.VBEditor;
@@ -74,15 +75,22 @@ public override int Compare(CodeExplorerItemViewModel x, CodeExplorerItemViewMod
7475
return xNode.Declaration.DeclarationType < yNode.Declaration.DeclarationType ? -1 : 1;
7576
}
7677

77-
// keep types with different icons and the same declaration type (document/class module) separate
78-
// documents come first
78+
if (xNode.Declaration.Accessibility != yNode.Declaration.Accessibility)
79+
{
80+
return xNode.Declaration.Accessibility < yNode.Declaration.Accessibility ? -1 : 1;
81+
}
82+
7983
if (x.ExpandedIcon != y.ExpandedIcon)
8084
{
81-
// ReSharper disable once PossibleInvalidOperationException - this will have a component
82-
return x.QualifiedSelection.Value.QualifiedName.Component.Type ==
83-
Microsoft.Vbe.Interop.vbext_ComponentType.vbext_ct_Document
84-
? -1
85-
: 1;
85+
// ReSharper disable PossibleInvalidOperationException - this will have a component
86+
var xComponent = x.QualifiedSelection.Value.QualifiedName.Component;
87+
var yComponent = y.QualifiedSelection.Value.QualifiedName.Component;
88+
89+
if (xComponent.Type == vbext_ComponentType.vbext_ct_Document ^
90+
yComponent.Type == vbext_ComponentType.vbext_ct_Document)
91+
{
92+
return xComponent.Type == vbext_ComponentType.vbext_ct_Document ? -1 : 1;
93+
}
8694
}
8795

8896
return 0;

RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@
274274
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
275275
<Setter Property="HorizontalAlignment" Value="Left" />
276276
<EventSetter Event="PreviewMouseRightButtonDown" Handler="OnPreviewMouseRightButtonDown" />
277+
<EventSetter Event="MouseDoubleClick" Handler="TreeView_OnMouseDoubleClick" />
277278
<Style.Triggers>
278279
<Trigger Property="IsSelected" Value="True">
279280
<Setter Property="BorderBrush" Value="#adc6e5"/>
@@ -726,7 +727,6 @@
726727
Background="White"
727728
ItemContainerStyle="{StaticResource ShinyTreeView}"
728729
HorizontalContentAlignment="Stretch"
729-
MouseDoubleClick="TreeView_OnMouseDoubleClick"
730730
Style="{StaticResource CodeExplorerTreeViewStyle}" BorderThickness="0,1"
731731
VirtualizingPanel.IsVirtualizing="False">
732732
<i:Interaction.Behaviors>

RetailCoder.VBE/UI/ToDoItems/ToDoExplorerViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public CommandBase RefreshCommand
107107

108108
private void _state_StateChanged(object sender, EventArgs e)
109109
{
110-
if (_state.Status != ParserState.Ready)
110+
if (_state.Status != ParserState.ResolvedDeclarations)
111111
{
112112
return;
113113
}

Rubberduck.Parsing/Symbols/Accessibility.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
{
33
public enum Accessibility
44
{
5-
Implicit,
6-
Private,
7-
Public,
8-
Global,
9-
Friend,
10-
Static,
5+
Private = 1,
6+
Friend = 2,
7+
Implicit = 3,
8+
Public = 4,
9+
Global = 5,
10+
Static = 6,
1111
}
1212
}

RubberduckTests/Inspections/VariableTypeNotDeclaredInspectionTests.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,38 @@ public void VariableTypeNotDeclared_QuickFixWorks_Parameter()
279279
Assert.AreEqual(expectedCode, actual);
280280
}
281281

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

0 commit comments

Comments
 (0)