@@ -130,7 +130,10 @@ namespace ts.formatting {
130
130
}
131
131
132
132
// check if current node is a list item - if yes, take indentation from it
133
- let actualIndentation = getActualIndentationForListItem ( current , sourceFile , options ) ;
133
+ // do not consider parent-child line sharing yet:
134
+ // function foo(a
135
+ // | preceding node 'a' does share line with its parent but indentation is expected
136
+ const actualIndentation = getActualIndentationForListItem ( current , sourceFile , options , /*listIndentsChild*/ true ) ;
134
137
if ( actualIndentation !== Value . Unknown ) {
135
138
return actualIndentation ;
136
139
}
@@ -171,22 +174,20 @@ namespace ts.formatting {
171
174
useActualIndentation = start < ignoreActualIndentationRange . pos || start > ignoreActualIndentationRange . end ;
172
175
}
173
176
174
- if ( useActualIndentation ) {
175
- // check if current node is a list item - if yes, take indentation from it
176
- const actualIndentation = getActualIndentationForListItem ( current , sourceFile , options ) ;
177
- if ( actualIndentation !== Value . Unknown ) {
178
- return actualIndentation + indentationDelta ;
179
- }
180
- }
181
-
182
177
const containingListOrParentStart = getContainingListOrParentStart ( parent , current , sourceFile ) ;
183
178
const parentAndChildShareLine =
184
179
containingListOrParentStart . line === currentStart . line ||
185
180
childStartsOnTheSameLineWithElseInIfStatement ( parent , current , currentStart . line , sourceFile ) ;
186
181
187
182
if ( useActualIndentation ) {
183
+ // check if current node is a list item - if yes, take indentation from it
184
+ let actualIndentation = getActualIndentationForListItem ( current , sourceFile , options , ! parentAndChildShareLine ) ;
185
+ if ( actualIndentation !== Value . Unknown ) {
186
+ return actualIndentation + indentationDelta ;
187
+ }
188
+
188
189
// try to fetch actual indentation for current node from source text
189
- let actualIndentation = getActualIndentationForNode ( current , parent , currentStart , parentAndChildShareLine , sourceFile , options ) ;
190
+ actualIndentation = getActualIndentationForNode ( current , parent , currentStart , parentAndChildShareLine , sourceFile , options ) ;
190
191
if ( actualIndentation !== Value . Unknown ) {
191
192
return actualIndentation + indentationDelta ;
192
193
}
@@ -407,13 +408,21 @@ namespace ts.formatting {
407
408
return findColumnForFirstNonWhitespaceCharacterInLine ( sourceFile . getLineAndCharacterOfPosition ( list . pos ) , sourceFile , options ) ;
408
409
}
409
410
410
- function getActualIndentationForListItem ( node : Node , sourceFile : SourceFile , options : EditorSettings ) : number {
411
+ function getActualIndentationForListItem ( node : Node , sourceFile : SourceFile , options : EditorSettings , listIndentsChild : boolean ) : number {
412
+ if ( node . parent && node . parent . kind === SyntaxKind . VariableDeclarationList ) {
413
+ // VariableDeclarationList has no wrapping tokens
414
+ return Value . Unknown ;
415
+ }
411
416
const containingList = getContainingList ( node , sourceFile ) ;
412
417
if ( containingList ) {
413
418
const index = containingList . indexOf ( node ) ;
414
419
if ( index !== - 1 ) {
415
- return deriveActualIndentationFromList ( containingList , index , sourceFile , options ) ;
420
+ const result = deriveActualIndentationFromList ( containingList , index , sourceFile , options ) ;
421
+ if ( result !== Value . Unknown ) {
422
+ return result ;
423
+ }
416
424
}
425
+ return getActualIndentationForListStartLine ( containingList , sourceFile , options ) + ( listIndentsChild ? options . indentSize : 0 ) ;
417
426
}
418
427
return Value . Unknown ;
419
428
}
0 commit comments