Change line limit to 80 char. And add a new strategy for printing method params to try to get under the 80 char limit. BUG= #592 R=rudominer@chromium.org Review URL: https://codereview.chromium.org/1770243002 .
diff --git a/mojo/public/tools/bindings/mojom_tool/bin/linux64/mojom.sha1 b/mojo/public/tools/bindings/mojom_tool/bin/linux64/mojom.sha1 index 346ce12..f53362f 100644 --- a/mojo/public/tools/bindings/mojom_tool/bin/linux64/mojom.sha1 +++ b/mojo/public/tools/bindings/mojom_tool/bin/linux64/mojom.sha1
@@ -1 +1 @@ -79987c1fd81b4941aee5c6ee08ee04d268ba64a3 \ No newline at end of file +9e6911a9eccee6ea393b995c6c98efa23705b746 \ No newline at end of file
diff --git a/mojo/public/tools/bindings/mojom_tool/bin/mac64/mojom.sha1 b/mojo/public/tools/bindings/mojom_tool/bin/mac64/mojom.sha1 index 7939d8e..71ff272 100644 --- a/mojo/public/tools/bindings/mojom_tool/bin/mac64/mojom.sha1 +++ b/mojo/public/tools/bindings/mojom_tool/bin/mac64/mojom.sha1
@@ -1 +1 @@ -bb5eb7d890b76a48e2699ff5d03f153f4c3ec66f \ No newline at end of file +98c2ff207f54471df774f6e10262f37e3ba5b92b \ No newline at end of file
diff --git a/mojom/mojom_parser/formatter/formatter_test.go b/mojom/mojom_parser/formatter/formatter_test.go index 1d31661..02da5f4 100644 --- a/mojom/mojom_parser/formatter/formatter_test.go +++ b/mojom/mojom_parser/formatter/formatter_test.go
@@ -34,12 +34,12 @@ int16 field2 = 10; // Field3 comment. // Field3 other comment. - int32 field3@10 = 10; + int32 field3@2 = 10; }; struct FooUnion { [Attr1=1] int8 field1; - int16 field2@5; + int16 field2@1; }; enum FooEnum { @@ -70,9 +70,9 @@ const int8 const_in_interface = 20; // Method 1 comment. - method1@5(int8 hello@10); + method1@5(int8 hello@0); // Method 2 comment. - method2([MinVersion=5] int8 hello) => (Foo bar@20); + method2([MinVersion=5] int8 hello) => (Foo bar@0); method3(); method4() => (Foo bar); method5(int8 p1 /* p1 comment */, int16 p2); // method comment
diff --git a/mojom/mojom_parser/formatter/printer.go b/mojom/mojom_parser/formatter/printer.go index 1ca4b3e..b4f243e 100644 --- a/mojom/mojom_parser/formatter/printer.go +++ b/mojom/mojom_parser/formatter/printer.go
@@ -63,7 +63,7 @@ // newPrinter is a constructor for printer. func newPrinter() (p *printer) { p = new(printer) - p.maxLineLength = 100 + p.maxLineLength = 80 return } @@ -240,6 +240,22 @@ extraIndent := p.lineLength() - p.indentSize if ownLine { + // If we are printing every parameter on its own line, check to see if + // aligning the parameters to the right of the method name can be done. + for _, param := range declaredObjects { + scratch := newPrinter() + scratch.maxLineLength = -1 + scratch.writeMethodParam(param.(*mojom.StructField)) + // If any parameter would go beyond the maximum line length, start the + // list of parameters on the line after the method name and indented 4 + // more than the method itself. + if len(scratch.result())+p.lineLength() > p.maxLineLength { + p.nl() + extraIndent = 4 + break + } + } + p.indentSize += extraIndent }