Skip to content

Commit cbbbcfa

Browse files
Fix incorrectly looking for position in call/new expression arguments when looking for indentation of type arguments (microsoft#34779)
* Fix incorrectly looking for position in call/new expression arguments when looking for indentation of type arguments Fixes microsoft#32487 * Update src/services/formatting/smartIndenter.ts Co-Authored-By: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
1 parent 05cbe5a commit cbbbcfa

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/services/formatting/smartIndenter.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,9 @@ namespace ts.formatting {
326326
export function argumentStartsOnSameLineAsPreviousArgument(parent: Node, child: TextRangeWithKind, childStartLine: number, sourceFile: SourceFileLike): boolean {
327327
if (isCallOrNewExpression(parent)) {
328328
if (!parent.arguments) return false;
329-
330-
const currentNode = Debug.assertDefined(find(parent.arguments, arg => arg.pos === child.pos));
329+
const currentNode = find(parent.arguments, arg => arg.pos === child.pos);
330+
// If it's not one of the arguments, don't look past this
331+
if (!currentNode) return false;
331332
const currentIndex = parent.arguments.indexOf(currentNode);
332333
if (currentIndex === 0) return false; // Can't look at previous node if first
333334

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
////const genericObject = new GenericObject<
4+
//// /*1*/{}
5+
////>();
6+
////const genericObject2 = new GenericObject2<
7+
//// /*2*/{},
8+
//// /*3*/{}
9+
////>();
10+
11+
format.document();
12+
13+
goTo.marker("1");
14+
verify.currentLineContentIs(" {}");
15+
goTo.marker("2");
16+
verify.currentLineContentIs(" {},");
17+
goTo.marker("3");
18+
verify.currentLineContentIs(" {}");

0 commit comments

Comments
 (0)