From 4ce4e47495e7c0dd574f87bbb5ba8aaec01c3c65 Mon Sep 17 00:00:00 2001 From: Magnus Hiie Date: Wed, 29 Mar 2017 20:20:32 +0300 Subject: [PATCH] Fix incorrect formatting in fluent API call Also add test cases (2nd test case with comma is currently commented out) Partially fixes #14675 --- src/services/formatting/formatting.ts | 4 ++++ .../fourslash/formattingOnChainedCallbacks.ts | 21 ++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index 4fa3b71a3a200..c8ea5da926f2e 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -461,6 +461,10 @@ namespace ts.formatting { else { indentation = parentDynamicIndentation.getIndentation() + parentDynamicIndentation.getDelta(node); } + if (node.kind === SyntaxKind.OpenParenToken) { + // if an open paren is on a different line from the call expression, indent the arguments one level deeper + delta = options.indentSize; + } } return { diff --git a/tests/cases/fourslash/formattingOnChainedCallbacks.ts b/tests/cases/fourslash/formattingOnChainedCallbacks.ts index b8dbc55d8b6cb..ee173f005c366 100644 --- a/tests/cases/fourslash/formattingOnChainedCallbacks.ts +++ b/tests/cases/fourslash/formattingOnChainedCallbacks.ts @@ -20,6 +20,14 @@ //// /*n2*/ //// .then(); +////Promise +//// .then( +//// /*cbNoComma*/cb +//// /*endNoComma*/) +//// .then( +//// /*cbComma*/cb, +//// /*endComma*/) +//// .then(); goTo.marker('1'); edit.insertLine(''); @@ -49,4 +57,15 @@ verify.currentLineContentIs(' });'); goTo.marker('n1'); verify.indentationIs(8); goTo.marker('n2'); -verify.indentationIs(4); \ No newline at end of file +verify.indentationIs(4); + +format.document(); + +goTo.marker('cbNoComma'); +verify.currentLineContentIs(' cb'); +goTo.marker('cbComma'); +verify.currentLineContentIs(' cb,'); +goTo.marker('endNoComma'); +verify.currentLineContentIs(' )'); +goTo.marker('endComma'); +// verify.currentLineContentIs(' )');