This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Discourage breaks in submessage entries
Needs ReviewPublic

Authored by krasimir on Jun 11 2018, 9:51 AM.
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

THIS IS JUST A SKETCH

Currently clang-format allows this for text protos:

submessage:
    { key: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' }

when it is under the column limit and when putting it all on one line exceeds the column limit.

This is not a very intuitive formatting, so I'd prefer having

submessage: {
  key: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
}

instead, even if it takes one line more.

This is just a rough sketch of an approach to achieve this: add a penalty for breaking before the {.
Want to discuss the validity of this approach.

Diff Detail

Event Timeline

krasimir created this revision.Jun 11 2018, 9:51 AM
krasimir edited the summary of this revision. (Show Details)Jun 11 2018, 9:53 AM
krasimir added reviewers: sammccall, djasper.

All else equal, I'd expect this to be a hard rule, at least in google-style.

"foo\n { a: b }" --> "foo {\n a: b\n}" only makes the first line longer, by 2 chars. So if 78 < indent + len("foo") <= 80 we're breaking the line limit, but that seems vanishingly rare.

If the penalty is sufficient to stop it happening almost always, maybe it works out the same.

All else equal, I'd expect this to be a hard rule, at least in google-style.

"foo\n { a: b }" --> "foo {\n a: b\n}" only makes the first line longer, by 2 chars. So if 78 < indent + len("foo") <= 80 we're breaking the line limit, but that seems vanishingly rare.

If the penalty is sufficient to stop it happening almost always, maybe it works out the same.

If we make this a hard rule, there's a better way: update canBreak to return false.