@@ -26,7 +26,7 @@ namespace ts.formatting {
26
26
precedingToken . kind === SyntaxKind . TemplateHead ||
27
27
precedingToken . kind === SyntaxKind . TemplateMiddle ||
28
28
precedingToken . kind === SyntaxKind . TemplateTail ;
29
- if ( precedingTokenIsLiteral && precedingToken . getStart ( sourceFile ) <= position && precedingToken . end > position ) {
29
+ if ( precedingTokenIsLiteral && precedingToken . getStart ( sourceFile ) <= position && precedingToken . end > position ) {
30
30
return 0 ;
31
31
}
32
32
@@ -66,6 +66,10 @@ namespace ts.formatting {
66
66
if ( actualIndentation !== Value . Unknown ) {
67
67
return actualIndentation ;
68
68
}
69
+ actualIndentation = getLineIndentationWhenExpressionIsInMultiLine ( current , sourceFile , options ) ;
70
+ if ( actualIndentation !== Value . Unknown ) {
71
+ return actualIndentation + options . IndentSize ;
72
+ }
69
73
70
74
previous = current ;
71
75
current = current . parent ;
@@ -122,6 +126,10 @@ namespace ts.formatting {
122
126
if ( actualIndentation !== Value . Unknown ) {
123
127
return actualIndentation + indentationDelta ;
124
128
}
129
+ actualIndentation = getLineIndentationWhenExpressionIsInMultiLine ( current , sourceFile , options ) ;
130
+ if ( actualIndentation !== Value . Unknown ) {
131
+ return actualIndentation + indentationDelta ;
132
+ }
125
133
}
126
134
127
135
// increase indentation if parent node wants its content to be indented and parent and child nodes don't start on the same line
@@ -287,6 +295,41 @@ namespace ts.formatting {
287
295
}
288
296
}
289
297
298
+ function getLineIndentationWhenExpressionIsInMultiLine ( node : Node , sourceFile : SourceFile , options : EditorOptions ) : number {
299
+ // actual indentation should not be used when:
300
+ // - node is close parenthesis - this is the end of the expression
301
+ // - node is property access expression
302
+ if ( node . kind !== SyntaxKind . CloseParenToken &&
303
+ node . kind !== SyntaxKind . PropertyAccessExpression &&
304
+ node . parent && (
305
+ node . parent . kind === SyntaxKind . CallExpression ||
306
+ node . parent . kind === SyntaxKind . NewExpression ) ) {
307
+
308
+ let parentExpression = ( < CallExpression | NewExpression > node . parent ) . expression ;
309
+ let startingExpression = getStartingExpression ( < PropertyAccessExpression | CallExpression | ElementAccessExpression > parentExpression ) ;
310
+
311
+ if ( parentExpression === startingExpression ) {
312
+ return Value . Unknown ;
313
+ }
314
+
315
+ let parentExpressionEnd = sourceFile . getLineAndCharacterOfPosition ( parentExpression . end ) ;
316
+ let startingExpressionEnd = sourceFile . getLineAndCharacterOfPosition ( startingExpression . end ) ;
317
+
318
+ if ( parentExpressionEnd . line === startingExpressionEnd . line ) {
319
+ return Value . Unknown ;
320
+ }
321
+
322
+ return findColumnForFirstNonWhitespaceCharacterInLine ( parentExpressionEnd , sourceFile , options ) ;
323
+ }
324
+ return Value . Unknown ;
325
+
326
+ function getStartingExpression ( expression : PropertyAccessExpression | CallExpression | ElementAccessExpression ) {
327
+ while ( expression . expression )
328
+ expression = < PropertyAccessExpression | CallExpression | ElementAccessExpression > expression . expression ;
329
+ return expression ;
330
+ }
331
+ }
332
+
290
333
function deriveActualIndentationFromList ( list : Node [ ] , index : number , sourceFile : SourceFile , options : EditorOptions ) : number {
291
334
Debug . assert ( index >= 0 && index < list . length ) ;
292
335
let node = list [ index ] ;
0 commit comments