@@ -26,7 +26,7 @@ namespace ts.formatting {
2626 precedingToken . kind === SyntaxKind . TemplateHead ||
2727 precedingToken . kind === SyntaxKind . TemplateMiddle ||
2828 precedingToken . kind === SyntaxKind . TemplateTail ;
29- if ( precedingTokenIsLiteral && precedingToken . getStart ( sourceFile ) <= position && precedingToken . end > position ) {
29+ if ( precedingTokenIsLiteral && precedingToken . getStart ( sourceFile ) <= position && precedingToken . end > position ) {
3030 return 0 ;
3131 }
3232
@@ -66,6 +66,10 @@ namespace ts.formatting {
6666 if ( actualIndentation !== Value . Unknown ) {
6767 return actualIndentation ;
6868 }
69+ actualIndentation = getLineIndentationWhenExpressionIsInMultiLine ( current , sourceFile , options ) ;
70+ if ( actualIndentation !== Value . Unknown ) {
71+ return actualIndentation + options . IndentSize ;
72+ }
6973
7074 previous = current ;
7175 current = current . parent ;
@@ -122,6 +126,10 @@ namespace ts.formatting {
122126 if ( actualIndentation !== Value . Unknown ) {
123127 return actualIndentation + indentationDelta ;
124128 }
129+ actualIndentation = getLineIndentationWhenExpressionIsInMultiLine ( current , sourceFile , options ) ;
130+ if ( actualIndentation !== Value . Unknown ) {
131+ return actualIndentation + indentationDelta ;
132+ }
125133 }
126134
127135 // 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,55 @@ namespace ts.formatting {
287295 }
288296 }
289297
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+ if ( node . kind === SyntaxKind . CloseParenToken ) {
302+ return Value . Unknown ;
303+ }
304+
305+ if ( node . parent && (
306+ node . parent . kind === SyntaxKind . CallExpression ||
307+ node . parent . kind === SyntaxKind . NewExpression ) &&
308+ ( < CallExpression > node . parent ) . expression !== node ) {
309+
310+ let fullCallOrNewExpression = ( < CallExpression | NewExpression > node . parent ) . expression ;
311+ let startingExpression = getStartingExpression ( < PropertyAccessExpression | CallExpression | ElementAccessExpression > fullCallOrNewExpression ) ;
312+
313+ if ( fullCallOrNewExpression === startingExpression ) {
314+ return Value . Unknown ;
315+ }
316+
317+ let fullCallOrNewExpressionEnd = sourceFile . getLineAndCharacterOfPosition ( fullCallOrNewExpression . end ) ;
318+ let startingExpressionEnd = sourceFile . getLineAndCharacterOfPosition ( startingExpression . end ) ;
319+
320+ if ( fullCallOrNewExpressionEnd . line === startingExpressionEnd . line ) {
321+ return Value . Unknown ;
322+ }
323+
324+ return findColumnForFirstNonWhitespaceCharacterInLine ( fullCallOrNewExpressionEnd , sourceFile , options ) ;
325+ }
326+
327+ return Value . Unknown ;
328+
329+ function getStartingExpression ( node : PropertyAccessExpression | CallExpression | ElementAccessExpression ) {
330+ while ( true ) {
331+ switch ( node . kind ) {
332+ case SyntaxKind . CallExpression :
333+ case SyntaxKind . NewExpression :
334+ case SyntaxKind . PropertyAccessExpression :
335+ case SyntaxKind . ElementAccessExpression :
336+
337+ node = < PropertyAccessExpression | CallExpression | ElementAccessExpression | PropertyAccessExpression > node . expression ;
338+ break ;
339+ default :
340+ return node ;
341+ }
342+ }
343+ return node ;
344+ }
345+ }
346+
290347 function deriveActualIndentationFromList ( list : Node [ ] , index : number , sourceFile : SourceFile , options : EditorOptions ) : number {
291348 Debug . assert ( index >= 0 && index < list . length ) ;
292349 let node = list [ index ] ;
0 commit comments