Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bcb9fd7

Browse filesBrowse files
alan-agius4Andy
authored andcommitted
fix: formatting for chaining methods (microsoft#21027)
Closes: microsoft#20996
1 parent f0ce80a commit bcb9fd7
Copy full SHA for bcb9fd7

2 files changed

+45-2Lines changed: 45 additions & 2 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/services/formatting/formatting.ts‎

Copy file name to clipboardExpand all lines: src/services/formatting/formatting.ts
+8-2Lines 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 => {
Collapse file
+37Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.