From 2e435ae3b0931b2ab79e2b12d53d44abfe03d711 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 28 Oct 2019 12:34:06 -0700 Subject: [PATCH 1/2] Fix incorrectly looking for position in call/new expression arguments when looking for indentation of type arguments Fixes #32487 --- src/services/formatting/smartIndenter.ts | 5 +++-- .../fourslash/formatTypeArgumentOnNewLine.ts | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 tests/cases/fourslash/formatTypeArgumentOnNewLine.ts diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index 6cc654453e41b..639d8f5ee44c8 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -326,8 +326,9 @@ namespace ts.formatting { export function argumentStartsOnSameLineAsPreviousArgument(parent: Node, child: TextRangeWithKind, childStartLine: number, sourceFile: SourceFileLike): boolean { if (isCallOrNewExpression(parent)) { if (!parent.arguments) return false; - - const currentNode = Debug.assertDefined(find(parent.arguments, arg => arg.pos === child.pos)); + const currentNode = find(parent.arguments, arg => arg.pos === child.pos); + // If its not one of the argument, dont look past this + if (!currentNode) return false; const currentIndex = parent.arguments.indexOf(currentNode); if (currentIndex === 0) return false; // Can't look at previous node if first diff --git a/tests/cases/fourslash/formatTypeArgumentOnNewLine.ts b/tests/cases/fourslash/formatTypeArgumentOnNewLine.ts new file mode 100644 index 0000000000000..8567a5ff06d68 --- /dev/null +++ b/tests/cases/fourslash/formatTypeArgumentOnNewLine.ts @@ -0,0 +1,18 @@ +/// + +////const genericObject = new GenericObject< +//// /*1*/{} +////>(); +////const genericObject2 = new GenericObject2< +//// /*2*/{}, +//// /*3*/{} +////>(); + +format.document(); + +goTo.marker("1"); +verify.currentLineContentIs(" {}"); +goTo.marker("2"); +verify.currentLineContentIs(" {},"); +goTo.marker("3"); +verify.currentLineContentIs(" {}"); \ No newline at end of file From 0bb1b40b1b2823261dc6bfc8e70e3a71839140f6 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 28 Oct 2019 13:39:17 -0700 Subject: [PATCH 2/2] Update src/services/formatting/smartIndenter.ts Co-Authored-By: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> --- src/services/formatting/smartIndenter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index 639d8f5ee44c8..5539a8e30cb2d 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -327,7 +327,7 @@ namespace ts.formatting { if (isCallOrNewExpression(parent)) { if (!parent.arguments) return false; const currentNode = find(parent.arguments, arg => arg.pos === child.pos); - // If its not one of the argument, dont look past this + // If it's not one of the arguments, don't look past this if (!currentNode) return false; const currentIndex = parent.arguments.indexOf(currentNode); if (currentIndex === 0) return false; // Can't look at previous node if first