@@ -132,10 +132,12 @@ public string Indented()
132
132
var current = _lines . First ( ) . Indent ( IndentationLevel , AtProcedureStart ) ;
133
133
var commentPos = string . IsNullOrEmpty ( _lines . First ( ) . EndOfLineComment ) ? 0 : current . Length - _lines . First ( ) . EndOfLineComment . Length ;
134
134
output . Add ( current ) ;
135
- var alignment = FunctionAlign ( current ) ;
135
+ var alignment = FunctionAlign ( current , _lines [ 1 ] . Original . Trim ( ) . StartsWith ( ":=" ) ) ;
136
136
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 ++ )
138
139
{
140
+ var line = _lines [ i ] ;
139
141
if ( line . IsDeclarationContinuation && ! line . IsProcedureStart )
140
142
{
141
143
output . Add ( line . Indent ( IndentationLevel , AtProcedureStart ) ) ;
@@ -154,7 +156,7 @@ public string Indented()
154
156
var operatorAdjust = _settings . IgnoreOperatorsInContinuations && OperatorIgnoreRegex . IsMatch ( line . Original ) ? 2 : 0 ;
155
157
current = line . Indent ( Math . Max ( alignment - operatorAdjust , 0 ) , AtProcedureStart , true ) ;
156
158
output . Add ( current ) ;
157
- alignment = FunctionAlign ( current ) ;
159
+ alignment = FunctionAlign ( current , i + 1 < _lines . Count && _lines [ i + 1 ] . Original . Trim ( ) . StartsWith ( ":=" ) ) ;
158
160
commentPos = string . IsNullOrEmpty ( line . EndOfLineComment ) ? 0 : current . Length - line . EndOfLineComment . Length ;
159
161
}
160
162
@@ -169,7 +171,8 @@ public override string ToString()
169
171
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+)" ) ;
170
172
private readonly Stack < AlignmentToken > _alignment = new Stack < AlignmentToken > ( ) ;
171
173
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 )
173
176
{
174
177
var stackPos = _alignment . Count ;
175
178
@@ -243,16 +246,14 @@ private int FunctionAlign(string line)
243
246
}
244
247
}
245
248
//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 )
247
250
{
248
251
while ( _alignment . Any ( ) && _alignment . Peek ( ) . Type == AlignmentTokenType . Parameter )
249
252
{
250
253
_alignment . Pop ( ) ;
251
254
}
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'
256
257
{
257
258
_alignment . Pop ( ) ;
258
259
_alignment . Pop ( ) ;
0 commit comments