Commit 7461dcda authored by Scott Graham's avatar Scott Graham

gn format: properly break and align multiple suffix comments

Previously

  a = [
    "x",
    "y",   # Comment1
           # Comment2
  ]

would turn into
  a = [
    "x",
    "y",   # Comment1# Comment2
  ]

(Child of https://codereview.chromium.org/606123002/)

R=brettw@chromium.org
BUG=348474

Review URL: https://codereview.chromium.org/613473002

Cr-Commit-Position: refs/heads/master@{#297235}
parent 930fcbcc
......@@ -122,14 +122,22 @@ void Printer::Newline() {
if (!comments_.empty()) {
Print(" ");
int i = 0;
// Save the margin, and temporarily set it to where the first comment
// starts so that multiple suffix comments are vertically aligned. This
// will need to be fancier once we enforce 80 col.
int old_margin = margin_;
for (const auto& c : comments_) {
if (i > 0) {
if (i == 0)
margin_ = CurrentColumn();
else {
Trim();
Print("\n");
PrintMargin();
}
TrimAndPrintToken(c);
++i;
}
margin_ = old_margin;
comments_.clear();
}
Trim();
......
......@@ -48,3 +48,4 @@ FORMAT_TEST(015)
FORMAT_TEST(017)
FORMAT_TEST(018)
FORMAT_TEST(019)
FORMAT_TEST(020)
cflags = [
"/wd4267", # size_t -> int.
"/wd4324", # Structure was padded due to __declspec(align()), which is
# uninteresting.
]
cflags = [
"/wd4267", # size_t -> int.
"/wd4324", # Structure was padded due to __declspec(align()), which is
# uninteresting.
]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment