This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] text protos: put entries on separate lines if there is a submessage
ClosedPublic

Authored by krasimir on May 11 2018, 7:37 AM.

Details

Summary

This patch updates clang-format text protos to put entries of a submessage into separate lines if the submessage contains at least two entries and contains at least one submessage entry.

For example, the entries here are kept on separate lines even if putting them on a single line would be under the column limit:

message: {
  entry: 1
  submessage: { key: value }
}

Messages containing a single submessage or several scalar entries can still be put on one line if they fit:

message { submessage { key: value } }
message { x: 1 y: 2 z: 3 }

Diff Detail

Event Timeline

krasimir created this revision.May 11 2018, 7:37 AM
krasimir updated this revision to Diff 150317.Jun 7 2018, 6:35 AM
  • Update comments
krasimir updated this revision to Diff 150320.Jun 7 2018, 6:41 AM
  • Add comments tests
krasimir retitled this revision from [clang-format] Break inside submessages containing a submessage and something else to [clang-format] text protos: put entries on separate lines if there is a submessage.Jun 7 2018, 6:46 AM
krasimir edited the summary of this revision. (Show Details)
krasimir edited the summary of this revision. (Show Details)
krasimir added a reviewer: sammccall.
sammccall accepted this revision.Jun 11 2018, 4:37 AM

LG

lib/Format/TokenAnnotator.cpp
2936

One more high-level piece could be added to this comment, e.g.

// We enforce this by breaking before a submessage field that has previous siblings, *and*
// breaking before a field that follows a submessage field.
2937

nit: the ] is the TT_SelectorName

2938

This could be slightly clearer I think...

... but we don't want to break inside the brackets. We ensure elsewhere that extensions are always on their own line.
2947

nit: this can't be a paren. calling it "brace" is probably ok

2977

nit: preceded

This revision is now accepted and ready to land.Jun 11 2018, 4:37 AM
krasimir updated this revision to Diff 150730.Jun 11 2018, 5:56 AM
krasimir marked 5 inline comments as done.
  • Address review comments
This revision was automatically updated to reflect the committed changes.