Allow shape to propagate through AssignPieces. #1694
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Consider:
Here we have a ListPiece for the
another(...)
call wrapped in an AssignPiece for the=>
wrapped in an AssignPiece for thename:
. When the inner ListPiece splits, it will be block-shaped. That in turn allows the surrounding AssignPiece to block format, giving:(If the ListPiece wasn't block-shaped, then the formatter would split after
=>
.)An interesting question is then "what is the shape of that AssignPiece?" Prior to this PR, the answer was always "other". Regardless of the shape of the AssignPiece's RHS, a split AssignPiece always had shape other. That meant that the entire original example would end up like:
Because the
(param) => ...
piece had shape "other", the AssignPiece for the named argument couldn't block format it, so it would split after the:
.That's not ideal. In practice with
=
and espectially with named arguments, users really want code on the same line as the argument name (and less indented) if at all possible.This PR propagates the shape of the AssignPiece's contents out to its surrounding context. This means that a headline-shaped RHS causes the assignment to be headline-shaped, and likewise for block-shaped. That lets the above example be formatted as:
Since
=
,:
, and=>
all use AssignPiece, this theoretically means that arbitrarily complex chains of those propagate the shape out. For example, chained assignments like this now work:In practice, 99% of the time this comes into play, it's a named argument whose expression is a
=>
function. But those are very common for callbacks in Flutter code, so this makes a big difference.Fix #1536.
Fix #1545.
Fix #1668.
Fix #1679.