Skip to content

Commit e8b987f

Browse files
committed
Ignore line numbers in continuations when indenting. Finishes handling of @ThunderFrame's evil bracketed identifier.
1 parent c68f71e commit e8b987f

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

Rubberduck.SmartIndenter/AbsoluteCodeLine.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ internal class AbsoluteCodeLine
3737
private List<string> _strings;
3838
private List<string> _brackets;
3939

40-
public AbsoluteCodeLine(string code, IIndenterSettings settings)
40+
public AbsoluteCodeLine(string code, IIndenterSettings settings) : this(code, settings, null) { }
41+
42+
public AbsoluteCodeLine(string code, IIndenterSettings settings, AbsoluteCodeLine previous)
4143
{
4244
_settings = settings;
45+
Previous = previous;
4346

4447
if (code.EndsWith(StupidLineEnding))
4548
{
@@ -56,6 +59,7 @@ public AbsoluteCodeLine(string code, IIndenterSettings settings)
5659
ExtractStringLiteralsAndBrackets();
5760
ExtractLineNumber();
5861
ExtractEndOfLineComment();
62+
5963
_code = Regex.Replace(_code, StringPlaceholder + "+", StringPlaceholder.ToString(CultureInfo.InvariantCulture));
6064
_code = Regex.Replace(_code, BracketPlaceholder + "+", BracketPlaceholder.ToString(CultureInfo.InvariantCulture)).Trim();
6165
_segments = _code.Split(new[] { ": " }, StringSplitOptions.None);
@@ -120,12 +124,15 @@ private void ExtractStringLiteralsAndBrackets()
120124

121125
private void ExtractLineNumber()
122126
{
123-
var match = LineNumberRegex.Match(_code);
124-
if (match.Success)
127+
if (Previous == null || !Previous.HasContinuation)
125128
{
126-
_numbered = true;
127-
_lineNumber = Convert.ToUInt32(match.Groups["number"].Value);
128-
_code = match.Groups["code"].Value;
129+
var match = LineNumberRegex.Match(_code);
130+
if (match.Success)
131+
{
132+
_numbered = true;
133+
_lineNumber = Convert.ToUInt32(match.Groups["number"].Value);
134+
_code = match.Groups["code"].Value;
135+
}
129136
}
130137
_code = _code.Trim();
131138
}
@@ -142,6 +149,8 @@ private void ExtractEndOfLineComment()
142149
EndOfLineComment = match.Groups["comment"].Value.Trim();
143150
}
144151

152+
public AbsoluteCodeLine Previous { get; private set; }
153+
145154
public string Original { get; private set; }
146155

147156
public string Escaped
@@ -203,7 +212,7 @@ public bool HasDeclarationContinuation
203212

204213
public bool HasContinuation
205214
{
206-
get { return _code.EndsWith(" _") || EndOfLineComment.EndsWith(" _"); }
215+
get { return _code.Equals("_") || _code.EndsWith(" _") || EndOfLineComment.EndsWith(" _"); }
207216
}
208217

209218
public bool IsPrecompilerDirective

Rubberduck.SmartIndenter/Indenter.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,11 @@ private IEnumerable<LogicalCodeLine> BuildLogicalCodeLines(IEnumerable<string> l
107107
var settings = _settings.Invoke();
108108
var logical = new List<LogicalCodeLine>();
109109
LogicalCodeLine current = null;
110+
AbsoluteCodeLine previous = null;
110111

111112
foreach (var line in lines)
112113
{
113-
var absolute = new AbsoluteCodeLine(line, settings);
114+
var absolute = new AbsoluteCodeLine(line, settings, previous);
114115
if (current == null)
115116
{
116117
current = new LogicalCodeLine(absolute, settings);
@@ -125,6 +126,7 @@ private IEnumerable<LogicalCodeLine> BuildLogicalCodeLines(IEnumerable<string> l
125126
{
126127
current = null;
127128
}
129+
previous = absolute;
128130
}
129131
return logical;
130132
}

RubberduckTests/SmartIndenter/MiscAndCornerCaseTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,6 @@ public void SingleQuoteInEndOfLineCommentWorks()
641641
[TestCategory("Indenter")]
642642
public void BracketedIdentifiersWork()
643643
{
644-
Assert.Inconclusive("Pending fix for line numbers on continuation lines, function aligning of declarations.");
645644
var code = new[]
646645
{
647646
"Sub test()",

0 commit comments

Comments
 (0)