File tree 3 files changed +15
-6
lines changed
RubberduckTests/SmartIndenter
3 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ public class AbsoluteCodeLine
26
26
private static readonly Regex PrecompilerInRegex = new Regex ( @"^#(Else)?If\s.+Then$|^#Else$" , RegexOptions . IgnoreCase ) ;
27
27
private static readonly Regex PrecompilerOutRegex = new Regex ( @"^#ElseIf\s.+Then|^#Else$|#End\sIf$" , RegexOptions . IgnoreCase ) ;
28
28
private static readonly Regex SingleLineElseIfRegex = new Regex ( @"^ElseIf\s.*\sThen\s.*" , RegexOptions . IgnoreCase ) ;
29
+ private static readonly Regex IfThenWithColonNoElseRegex = new Regex ( @"If\s.*\sThen:\s(?!.*:\sElse(If)?)" , RegexOptions . IgnoreCase ) ;
29
30
30
31
private readonly IIndenterSettings _settings ;
31
32
private int _lineNumber ;
@@ -192,6 +193,8 @@ public bool IsProcedureEnd
192
193
193
194
public bool IsEmpty => Original . Trim ( ) . Length == 0 ;
194
195
196
+ public bool ContainsIfThenWithColonNoElse => IfThenWithColonNoElseRegex . IsMatch ( _code ) ;
197
+
195
198
public int NextLineIndents
196
199
{
197
200
get
Original file line number Diff line number Diff line change @@ -51,9 +51,16 @@ public int NextLineIndents
51
51
{
52
52
return 0 ;
53
53
}
54
- return _rebuilt . Segments . Count ( ) < 2
54
+ var indents = _rebuilt . Segments . Count ( ) < 2
55
55
? _rebuilt . NextLineIndents
56
56
: _rebuilt . Segments . Select ( s => new AbsoluteCodeLine ( s , _settings ) ) . Select ( a => a . NextLineIndents ) . Sum ( ) ;
57
+
58
+ if ( _rebuilt . ContainsIfThenWithColonNoElse )
59
+ {
60
+ indents -- ;
61
+ }
62
+ return indents ;
63
+
57
64
}
58
65
}
59
66
Original file line number Diff line number Diff line change @@ -83,25 +83,24 @@ public void UnmatchedEnumsNotIndent()
83
83
Assert . IsTrue ( code . SequenceEqual ( actual ) ) ;
84
84
}
85
85
86
+ // https://github.com/rubberduck-vba/Rubberduck/issues/5929
86
87
[ Test ] // Broken in VB6 SmartIndenter.
87
88
[ Category ( "Indenter" ) ]
88
89
public void IfThenElseOnSameLineWorks ( )
89
90
{
90
91
var code = new [ ]
91
92
{
92
93
"Public Sub Test()" ,
93
- "If Foo = 42 Then: Bar = Foo: Else" ,
94
+ "If Foo = 42 Then: Bar = Foo: Else Baz = Bar " ,
94
95
"Baz = Foo" ,
95
- "End If" ,
96
96
"End Sub"
97
97
} ;
98
98
99
99
var expected = new [ ]
100
100
{
101
101
"Public Sub Test()" ,
102
- " If Foo = 42 Then: Bar = Foo: Else" ,
103
- " Baz = Foo" ,
104
- " End If" ,
102
+ " If Foo = 42 Then: Bar = Foo: Else Baz = Bar" ,
103
+ " Baz = Foo" ,
105
104
"End Sub"
106
105
} ;
107
106
You can’t perform that action at this time.
0 commit comments