Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions experimental/ast/printer/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ func (p *printer) printArray(expr ast.ExprArray, gap gapStyle) {
}

hasComments := triviaHasComments(slots)
// Also check for comments attached to any token in the scope
// (trailing on open bracket, leading on close bracket, or on any
// interior token). These force multi-line expansion.
if !hasComments {
hasComments = p.scopeHasAttachedComments(brackets)
}

if elements.Len() == 0 && !hasComments {
p.printToken(openTok, gap)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ message Test {
foo: "goo" // Trailing comment on foo

// Leading comment on extension name.
[/* One */ foo.bar.Test.Nested._NestedNested._garblez /* Two */] /* Three */ : "boo" // Trailing comment on extension name.
[
/* One */
foo.bar.Test.Nested._NestedNested._garblez
/* Two */
] /* Three */ : "boo" // Trailing comment on extension name.

// Leading comment on '}'.
};
Expand Down
7 changes: 7 additions & 0 deletions experimental/ast/printer/testdata/format/array_comment.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
syntax = "proto3";

option (any) = {
array: [
"x" // comment
]
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
syntax = "proto3";

option (any) = {
array: [
"x" // comment
]
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
syntax = "proto3";

option (any) = {
array: [
"x" // comment
]
};
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ message Foo {
foo: "goo" // Trailing comment on foo

// Leading comment on extension name.
[/* One */ foo.bar.Test.Nested._NestedNested._garblez /* Two */] /* Three */ : "boo" // Trailing comment on extension name.
[
/* One */
foo.bar.Test.Nested._NestedNested._garblez /* Two */
] /* Three */ : "boo" // Trailing comment on extension name.

// Leading comment on '}'.
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ message Foo {
foo: "goo" // Trailing comment on foo

// Leading comment on extension name.
[/* One */ foo.bar.Test.Nested._NestedNested._garblez /* Two */] /* Three */ : "boo" // Trailing comment on extension name.
[
/* One */
foo.bar.Test.Nested._NestedNested._garblez
/* Two */
] /* Three */ : "boo" // Trailing comment on extension name.

// Leading comment on '}'.
};
Expand Down
Loading