Skip to content

Commit bcb9fd7

Browse files
alan-agius4Andy
authored and
Andy
committed
fix: formatting for chaining methods (#21027)
Closes: #20996
1 parent f0ce80a commit bcb9fd7

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

src/services/formatting/formatting.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,13 @@ namespace ts.formatting {
484484
delta = Math.min(options.indentSize, parentDynamicIndentation.getDelta(node) + delta);
485485
}
486486
else if (indentation === Constants.Unknown) {
487-
if (SmartIndenter.childStartsOnTheSameLineWithElseInIfStatement(parent, node, startLine, sourceFile)) {
487+
if (node.kind === SyntaxKind.OpenParenToken && startLine === lastIndentedLine) {
488+
// the is used for chaining methods formatting
489+
// - we need to get the indentation on last line and the delta of parent
490+
indentation = indentationOnLastIndentedLine;
491+
delta = parentDynamicIndentation.getDelta(node);
492+
}
493+
else if (SmartIndenter.childStartsOnTheSameLineWithElseInIfStatement(parent, node, startLine, sourceFile)) {
488494
indentation = parentDynamicIndentation.getIndentation();
489495
}
490496
else {
@@ -622,7 +628,7 @@ namespace ts.formatting {
622628
let childContextNode = contextNode;
623629

624630
// if there are any tokens that logically belong to node and interleave child nodes
625-
// such tokens will be consumed in processChildNode for for the child that follows them
631+
// such tokens will be consumed in processChildNode for the child that follows them
626632
forEachChild(
627633
node,
628634
child => {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
//// z$ = this.store.select(this.fake())
4+
//// .ofType(
5+
//// 'ACTION',
6+
//// 'ACTION-2'
7+
//// )
8+
//// .pipe(
9+
//// filter(x => !!x),
10+
//// switchMap(() =>
11+
//// this.store.select(this.menuSelector.getAll('x'))
12+
//// .pipe(
13+
//// tap(x => {
14+
//// this.x = !x;
15+
//// })
16+
//// )
17+
//// )
18+
//// );
19+
20+
format.document();
21+
verify.currentFileContentIs(`z$ = this.store.select(this.fake())
22+
.ofType(
23+
'ACTION',
24+
'ACTION-2'
25+
)
26+
.pipe(
27+
filter(x => !!x),
28+
switchMap(() =>
29+
this.store.select(this.menuSelector.getAll('x'))
30+
.pipe(
31+
tap(x => {
32+
this.x = !x;
33+
})
34+
)
35+
)
36+
);`
37+
);

0 commit comments

Comments
 (0)