Skip to content

Commit 890c2d2

Browse files
committed
Fix indenting of multi-segment Do...Loop, If...Then...Else
1 parent 6025e44 commit 890c2d2

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

Rubberduck.SmartIndenter/AbsoluteCodeLine.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,14 @@ private void ExtractEndOfLineComment()
8787
}
8888

8989
public string Original { get; private set; }
90+
9091
public string EndOfLineComment { get; private set; }
9192

93+
public IEnumerable<string> Segments
94+
{
95+
get { return _segments; }
96+
}
97+
9298
public string ContinuationRebuildText
9399
{
94100
get

Rubberduck.SmartIndenter/LogicalCodeLine.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ public int NextLineIndents
3535
get
3636
{
3737
RebuildContinuedLine();
38-
return _rebuilt.NextLineIndents;
38+
return _rebuilt.Segments.Count() < 2
39+
? _rebuilt.NextLineIndents
40+
: _rebuilt.Segments.Select(s => new AbsoluteCodeLine(s, _settings)).Select(a => a.NextLineIndents).Sum();
3941
}
4042
}
4143

@@ -44,7 +46,12 @@ public int Outdents
4446
get
4547
{
4648
RebuildContinuedLine();
47-
return _rebuilt.Outdents;
49+
if (_rebuilt.Segments.Count() < 2)
50+
{
51+
return _rebuilt.Outdents;
52+
}
53+
var baseSegment = new AbsoluteCodeLine(_rebuilt.Segments.First(), _settings);
54+
return baseSegment.Outdents;
4855
}
4956
}
5057

RubberduckTests/SmartIndenter/LineContinuationTests.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ public void RemsWithLineContinuationsWork()
261261
Assert.IsTrue(code.SequenceEqual(actual));
262262
}
263263

264-
[TestMethod, Ignore] // Broken in VB6 SmartIndenter. Should be same fix as IfThenElseOnSameLineWorks()
264+
[TestMethod] // Broken in VB6 SmartIndenter.
265265
[TestCategory("Indenter")]
266266
public void DoWhileOnTwoLinesWorks()
267267
{
@@ -274,12 +274,11 @@ public void DoWhileOnTwoLinesWorks()
274274
"End Sub"
275275
};
276276

277-
//TODO: Not sure if this is what should be expected...
278277
var expected = new[]
279278
{
280279
"Public Sub Test()",
281280
" Do _",
282-
" While X < 10: X = X + 1: Loop",
281+
" While X < 10: X = X + 1: Loop",
283282
" Debug.Print X",
284283
"End Sub"
285284
};
@@ -289,7 +288,7 @@ public void DoWhileOnTwoLinesWorks()
289288
Assert.IsTrue(expected.SequenceEqual(actual));
290289
}
291290

292-
[TestMethod] // Broken in VB6 SmartIndenter.
291+
[TestMethod] // Broken in VB6 SmartIndenter.
293292
[TestCategory("Indenter")]
294293
public void ContinuedIfThenWorks()
295294
{

RubberduckTests/SmartIndenter/MultiSegmentLineTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void UnmatchedEnumsNotIndent()
6868
Assert.IsTrue(code.SequenceEqual(actual));
6969
}
7070

71-
[TestMethod, Ignore] // Broken in VB6 SmartIndenter. Should be same fix as DoWhileOnTwoLinesWorks()
71+
[TestMethod] // Broken in VB6 SmartIndenter.
7272
[TestCategory("Indenter")]
7373
public void IfThenElseOnSameLineWorks()
7474
{

0 commit comments

Comments
 (0)