diff options
author | Scott Graham <scottmg@chromium.org> | 2014-09-29 12:36:34 -0700 |
---|---|---|
committer | Scott Graham <scottmg@chromium.org> | 2014-09-29 19:37:53 +0000 |
commit | 7461dcda6673ccd78b82efc4719e1389fc0c215b (patch) | |
tree | 908868c5bffc076dffa83e12b2dd5675644983b2 | |
parent | 930fcbcccbb7a4c0c8892acf175503555099e29c (diff) | |
download | chromium_src-7461dcda6673ccd78b82efc4719e1389fc0c215b.zip chromium_src-7461dcda6673ccd78b82efc4719e1389fc0c215b.tar.gz chromium_src-7461dcda6673ccd78b82efc4719e1389fc0c215b.tar.bz2 |
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}
-rw-r--r-- | tools/gn/command_format.cc | 10 | ||||
-rw-r--r-- | tools/gn/command_format_unittest.cc | 1 | ||||
-rw-r--r-- | tools/gn/format_test_data/020.gn | 5 | ||||
-rw-r--r-- | tools/gn/format_test_data/020.golden | 5 |
4 files changed, 20 insertions, 1 deletions
diff --git a/tools/gn/command_format.cc b/tools/gn/command_format.cc index 96170b2..0a110f1 100644 --- a/tools/gn/command_format.cc +++ b/tools/gn/command_format.cc @@ -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(); diff --git a/tools/gn/command_format_unittest.cc b/tools/gn/command_format_unittest.cc index 4c59c28..bb9c6fd 100644 --- a/tools/gn/command_format_unittest.cc +++ b/tools/gn/command_format_unittest.cc @@ -48,3 +48,4 @@ FORMAT_TEST(015) FORMAT_TEST(017) FORMAT_TEST(018) FORMAT_TEST(019) +FORMAT_TEST(020) diff --git a/tools/gn/format_test_data/020.gn b/tools/gn/format_test_data/020.gn new file mode 100644 index 0000000..96de164 --- /dev/null +++ b/tools/gn/format_test_data/020.gn @@ -0,0 +1,5 @@ +cflags = [ + "/wd4267", # size_t -> int. + "/wd4324", # Structure was padded due to __declspec(align()), which is + # uninteresting. +] diff --git a/tools/gn/format_test_data/020.golden b/tools/gn/format_test_data/020.golden new file mode 100644 index 0000000..96de164 --- /dev/null +++ b/tools/gn/format_test_data/020.golden @@ -0,0 +1,5 @@ +cflags = [ + "/wd4267", # size_t -> int. + "/wd4324", # Structure was padded due to __declspec(align()), which is + # uninteresting. +] |