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

Unified Diff: tools/json_schema_compiler/code.py

Issue 1010603007: [Extension API Extern Generation] Fix comment indentation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/json_schema_compiler/code_test.py » ('j') | tools/json_schema_compiler/code_test.py » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/json_schema_compiler/code.py
diff --git a/tools/json_schema_compiler/code.py b/tools/json_schema_compiler/code.py
index 8ce6afab675e61620199e2328cdfe7338b9b1236..175aea17700849eff1b48fea56000d4a780f183b 100644
--- a/tools/json_schema_compiler/code.py
+++ b/tools/json_schema_compiler/code.py
@@ -85,7 +85,7 @@ class Code(object):
self.Append(line)
return self
- def Comment(self, comment, comment_prefix='// '):
+ def Comment(self, comment, comment_prefix='// ', wrap_indent=0):
"""Adds the given string as a comment.
Will split the comment if it's too long. Use mainly for variable length
@@ -93,8 +93,11 @@ class Code(object):
Unaffected by code.Substitute().
"""
- max_len = self._comment_length - self._indent_level - len(comment_prefix)
- while len(comment) >= max_len:
+ # Helper function to trim a comment to the maximum length, and return one
+ # line and the remainder of the comment.
+ def trim_comment(comment, max_len):
+ if len(comment) <= max_len:
+ return comment, ''
line = comment[0:max_len]
Devlin 2015/03/26 22:36:54 Technically, this means treats the max length as 1
Dan Beam 2015/03/26 22:41:48 i think 80 is fine...?
Devlin 2015/03/26 23:13:08 Thought so, but figured good to double check.
last_space = line.rfind(' ')
if last_space != -1:
@@ -102,8 +105,19 @@ class Code(object):
comment = comment[last_space + 1:]
else:
comment = comment[max_len:]
- self.Append(comment_prefix + line, substitute=False)
- self.Append(comment_prefix + comment, substitute=False)
+ return line, comment
+
+ # First line has the full maximum length.
+ max_len = self._comment_length - self._indent_level - len(comment_prefix)
+ line, comment = trim_comment(comment, max_len)
+ self.Append(comment_prefix + line, substitute=False)
+
+ # Any subsequent lines be subject to the wrap indent.
+ max_len = max_len - wrap_indent
+ while len(comment):
+ line, comment = trim_comment(comment, max_len)
+ self.Append(comment_prefix + (' ' * wrap_indent) + line, substitute=False)
+
return self
def Substitute(self, d):
« no previous file with comments | « no previous file | tools/json_schema_compiler/code_test.py » ('j') | tools/json_schema_compiler/code_test.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698