Skip to content

Fix formatting of parameter list of a multiple-line call expression #14955

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from

Conversation

zhengbli
Copy link
Contributor

Fixes #14675

@zhengbli zhengbli force-pushed the fixFormatCallExpression branch from df2da92 to adeb9a6 Compare March 31, 2017 22:00
@magnushiie
Copy link
Contributor

This works great, thank you!

@magnushiie
Copy link
Contributor

One additional (somewhat related, but I understand this is PropertyAccessExpression vs ElementAccessExpression, not about CallExpression) question, shouldn't the following be formatted the same way?

Promise
['then'](
  cb
);

Promise
['then'](
  cb,
);

@zhengbli
Copy link
Contributor Author

zhengbli commented Apr 3, 2017

Yes that does make sense, I'll try to cover this case and update later. Thanks for pointing out!

case SyntaxKind.CallExpression:
return (<CallExpression>parent).arguments === nodes;
default:
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: would merge this with the if clause above.

* Here the parent of argument list is the call expression itself, however the indentation of the argument list should carry
* over the indentation in line 1 (".then").
*/
function shouldListInheritIndentationFromLastIndentedLine(listStartLine: number, parent: Node, nodes: NodeArray<Node>) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you comment with an above example what is the value of "listStartLine"?

@@ -732,6 +762,13 @@ namespace ts.formatting {
inheritedIndentation = processChildNode(child, inheritedIndentation, node, listDynamicIndentation, startLine, startLine, /*isListItem*/ true, /*isFirstListItem*/ i === 0);
}

if (nodes.hasTrailingComma && formattingScanner.isOnToken()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this clause is so that we will indent trailing comma appropriately?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. The current issue is the formatter does not expect a trailing comma; it checks after all children nodes if the the current token is not the expected list ending token, it will do nothing. And then the list end token will be formatted later as part of the parent node using the parent's dynamic indentations. It worked fine before most of the time because normally the list uses the same indentation with its parent node; however, in this particular case they are different, therefore the trailing comma is causing problems. This change is to ensure that the list end token is processed with the list not its parent.

@saschanaz
Copy link
Contributor

Sorry to bother you, but I think this is kind of duplicated work of #13574?

@zhengbli
Copy link
Contributor Author

@saschanaz Hmm I was not aware of your PR. I'll take a look and if it covers my fix I'll close this. Thanks.

@magnushiie
Copy link
Contributor

Is this or #13574 going to be merged some time?

@typescript-bot
Copy link
Collaborator

Thanks for your contribution. This PR has not been updated in a while and cannot be automatically merged at the time being. For housekeeping purposes we are closing stale PRs. If you'd still like to continue working on this PR, please leave a message and one of the maintainers can reopen it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants