This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Discourage breaks in submessage entries, hard rule
ClosedPublic

Authored by krasimir on Jun 12 2018, 1:32 AM.

Details

Summary

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 patch prevents clang-format from inserting a break between : { and similar cases.

Diff Detail

Repository
rL LLVM

Event Timeline

krasimir created this revision.Jun 12 2018, 1:32 AM
krasimir edited the summary of this revision. (Show Details)Jun 12 2018, 3:29 AM
krasimir updated this revision to Diff 150926.Jun 12 2018, 3:45 AM
  • Add tests
sammccall accepted this revision.Jun 12 2018, 10:21 AM
sammccall added inline comments.
lib/Format/TokenAnnotator.cpp
3104 ↗(On Diff #150926)

It's really hard to follow the boolean logic here.
Can you break this up into multiple if statements with comments, or extract some named subexpressions or something? e.g.

if (proto or textproto) {
  if (bool isSubmessage = ...)
    return false;
  if (right is string && !break before multiline)
    return false;
  return true;
}
This revision is now accepted and ready to land.Jun 12 2018, 10:21 AM
krasimir updated this revision to Diff 150980.Jun 12 2018, 10:29 AM
  • Split-up the if-condition
krasimir marked an inline comment as done.Jun 12 2018, 10:29 AM
This revision was automatically updated to reflect the committed changes.