Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(295)

Side by Side Diff: tools/gn/command_format.cc

Issue 613473002: gn format: properly break and align multiple suffix comments (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gn-list-comment-spacing
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools/gn/command_format_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <sstream> 5 #include <sstream>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "tools/gn/commands.h" 8 #include "tools/gn/commands.h"
9 #include "tools/gn/input_file.h" 9 #include "tools/gn/input_file.h"
10 #include "tools/gn/parser.h" 10 #include "tools/gn/parser.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 void Printer::TrimAndPrintToken(const Token& token) { 115 void Printer::TrimAndPrintToken(const Token& token) {
116 std::string trimmed; 116 std::string trimmed;
117 TrimWhitespaceASCII(token.value().as_string(), base::TRIM_ALL, &trimmed); 117 TrimWhitespaceASCII(token.value().as_string(), base::TRIM_ALL, &trimmed);
118 Print(trimmed); 118 Print(trimmed);
119 } 119 }
120 120
121 void Printer::Newline() { 121 void Printer::Newline() {
122 if (!comments_.empty()) { 122 if (!comments_.empty()) {
123 Print(" "); 123 Print(" ");
124 int i = 0; 124 int i = 0;
125 // Save the margin, and temporarily set it to where the first comment
126 // starts so that multiple suffix comments are vertically aligned. This
127 // will need to be fancier once we enforce 80 col.
128 int old_margin = margin_;
125 for (const auto& c : comments_) { 129 for (const auto& c : comments_) {
126 if (i > 0) { 130 if (i == 0)
131 margin_ = CurrentColumn();
132 else {
127 Trim(); 133 Trim();
128 Print("\n"); 134 Print("\n");
129 PrintMargin(); 135 PrintMargin();
130 } 136 }
131 TrimAndPrintToken(c); 137 TrimAndPrintToken(c);
138 ++i;
132 } 139 }
140 margin_ = old_margin;
133 comments_.clear(); 141 comments_.clear();
134 } 142 }
135 Trim(); 143 Trim();
136 Print("\n"); 144 Print("\n");
137 PrintMargin(); 145 PrintMargin();
138 } 146 }
139 147
140 void Printer::Trim() { 148 void Printer::Trim() {
141 size_t n = output_.size(); 149 size_t n = output_.size();
142 while (n > 0 && output_[n - 1] == ' ') 150 while (n > 0 && output_[n - 1] == ' ')
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 } 428 }
421 std::string output_string; 429 std::string output_string;
422 if (FormatFileToString(input_name, dump_tree, &output_string)) { 430 if (FormatFileToString(input_name, dump_tree, &output_string)) {
423 printf("%s", output_string.c_str()); 431 printf("%s", output_string.c_str());
424 } 432 }
425 433
426 return 0; 434 return 0;
427 } 435 }
428 436
429 } // namespace commands 437 } // namespace commands
OLDNEW
« no previous file with comments | « no previous file | tools/gn/command_format_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698