Skip to content

Commit 14b0270

Browse files
committed
Fix alignment of split named parameters in indenter.
1 parent 5fb03fb commit 14b0270

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

Rubberduck.SmartIndenter/LogicalCodeLine.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,12 @@ public string Indented()
132132
var current = _lines.First().Indent(IndentationLevel, AtProcedureStart);
133133
var commentPos = string.IsNullOrEmpty(_lines.First().EndOfLineComment) ? 0 : current.Length - _lines.First().EndOfLineComment.Length;
134134
output.Add(current);
135-
var alignment = FunctionAlign(current);
135+
var alignment = FunctionAlign(current, _lines[1].Original.Trim().StartsWith(":="));
136136

137-
foreach (var line in _lines.Skip(1))
137+
//foreach (var line in _lines.Skip(1))
138+
for (var i = 1; i < _lines.Count; i++)
138139
{
140+
var line = _lines[i];
139141
if (line.IsDeclarationContinuation && !line.IsProcedureStart)
140142
{
141143
output.Add(line.Indent(IndentationLevel, AtProcedureStart));
@@ -154,7 +156,7 @@ public string Indented()
154156
var operatorAdjust = _settings.IgnoreOperatorsInContinuations && OperatorIgnoreRegex.IsMatch(line.Original) ? 2 : 0;
155157
current = line.Indent(Math.Max(alignment - operatorAdjust, 0), AtProcedureStart, true);
156158
output.Add(current);
157-
alignment = FunctionAlign(current);
159+
alignment = FunctionAlign(current, i + 1 < _lines.Count && _lines[i + 1].Original.Trim().StartsWith(":="));
158160
commentPos = string.IsNullOrEmpty(line.EndOfLineComment) ? 0 : current.Length - line.EndOfLineComment.Length;
159161
}
160162

@@ -169,7 +171,8 @@ public override string ToString()
169171
private static readonly Regex StartIgnoreRegex = new Regex(@"^(\d*\s)?\s*[LR]?Set\s|^(\d*\s)?\s*Let\s|^(\d*\s)?\s*(Public|Private)\sDeclare\s(Function|Sub)|^(\d*\s+)");
170172
private readonly Stack<AlignmentToken> _alignment = new Stack<AlignmentToken>();
171173

172-
private int FunctionAlign(string line)
174+
//The splitNamed parameter is a straight up hack for fixing https://github.com/rubberduck-vba/Rubberduck/issues/2402
175+
private int FunctionAlign(string line, bool splitNamed)
173176
{
174177
var stackPos = _alignment.Count;
175178

@@ -243,16 +246,14 @@ private int FunctionAlign(string line)
243246
}
244247
}
245248
//If we end with a comma or a named parameter, get rid of all other comma alignments
246-
if (line.EndsWith(", _") || line.EndsWith(":= _"))
249+
if (line.EndsWith(", _") || line.EndsWith(":= _") || splitNamed)
247250
{
248251
while (_alignment.Any() && _alignment.Peek().Type == AlignmentTokenType.Parameter)
249252
{
250253
_alignment.Pop();
251254
}
252-
}
253-
254-
//If we end with a "( _", remove it and the space alignment after it
255-
if (line.EndsWith("( _"))
255+
}
256+
else if (line.EndsWith("( _")) //If we end with a "( _", remove it and the space alignment after it'
256257
{
257258
_alignment.Pop();
258259
_alignment.Pop();

0 commit comments

Comments
 (0)