Skip to content

Commit

Permalink
protoprint: fix bug where comments on method options were not include…
Browse files Browse the repository at this point in the history
…d in output (#492)
  • Loading branch information
jhump authored Feb 13, 2022
1 parent 6224817 commit 0e352eb
Show file tree
Hide file tree
Showing 32 changed files with 224 additions and 225 deletions.
230 changes: 123 additions & 107 deletions desc/protoparse/test-source-info.txt

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions desc/protoprint/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -1417,14 +1417,14 @@ func (p *Printer) printMethod(mtd *desc.MethodDescriptor, mf *dynamic.MessageFac
elements := elementAddrs{dsc: mtd, opts: opts}
elements.addrs = optionsAsElementAddrs(internal.Method_optionsTag, 0, opts)
p.sort(elements, sourceInfo, path)
path = append(path, internal.Method_optionsTag)

for i, addr := range elements.addrs {
for i, el := range elements.addrs {
if i > 0 {
p.newLine(w)
}
o := elements.at(addr).([]option)
p.printOptionsLong(o, w, sourceInfo, path, indent)
o := elements.at(el).([]option)
childPath := append(path, el.elementType, int32(el.elementIndex))
p.printOptionsLong(o, w, sourceInfo, childPath, indent)
}

p.indent(w, indent-1)
Expand Down
3 changes: 3 additions & 0 deletions desc/protoprint/testfiles/desc_test_comments-compact.proto
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ message Request {
}
// can be these or those
oneof xyz {
// whoops?
option (testprotos.oofubar) = "whoops!";
string these = 6;
int32 those = 7;
}
Expand Down Expand Up @@ -92,6 +94,7 @@ service RpcService {
rpc StreamingRpc ( stream Request ) returns ( Request ); // compact method trailer
rpc UnaryRpc ( Request ) returns ( google.protobuf.Empty ) {
// trailer for method
// this RPC is deprecated!
option deprecated = true;
option (testprotos.mtfubar) = 12.340000;
option (testprotos.mtfubard) = 123.456000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ service RpcService {

option (testprotos.mtfubar) = 12.340000;

// this RPC is deprecated!
option deprecated = true;
}

Expand Down Expand Up @@ -96,6 +97,9 @@ message Request {
int32 those = 7;

string these = 6;

// whoops?
option (testprotos.oofubar) = "whoops!";
}

// can be this or that
Expand Down
4 changes: 4 additions & 0 deletions desc/protoprint/testfiles/desc_test_comments-default.proto
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ message Request {

// can be these or those
oneof xyz {
// whoops?
option (testprotos.oofubar) = "whoops!";

string these = 6;

int32 those = 7;
Expand Down Expand Up @@ -150,6 +153,7 @@ service RpcService {
rpc UnaryRpc ( Request ) returns ( google.protobuf.Empty ) {
// trailer for method

// this RPC is deprecated!
option deprecated = true;

option (testprotos.mtfubar) = 12.340000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ message Request {

/* can be these or those */
oneof xyz {
/* whoops? */
option (testprotos.oofubar) = "whoops!";

string these = 6;

int32 those = 7;
Expand Down Expand Up @@ -154,6 +157,7 @@ service RpcService {
rpc UnaryRpc ( Request ) returns ( google.protobuf.Empty ) {
/* trailer for method */

/* this RPC is deprecated! */
option deprecated = true;

option (testprotos.mtfubar) = 12.340000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ message Request {

// can be these or those
oneof xyz {
// whoops?
option (testprotos.oofubar) = "whoops!";

string these = 6;

int32 those = 7;
Expand Down Expand Up @@ -137,6 +140,7 @@ service RpcService {
rpc StreamingRpc ( stream Request ) returns ( Request );

rpc UnaryRpc ( Request ) returns ( google.protobuf.Empty ) {
// this RPC is deprecated!
option deprecated = true;

option (testprotos.mtfubar) = 12.340000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ message Request {

// can be these or those
oneof xyz {
option (testprotos.oofubar) = "whoops!";

string these = 6;

int32 those = 7;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ message Request {

/* can be these or those */
oneof xyz {
/* whoops? */
option (testprotos.oofubar) = "whoops!";

string these = 6;

int32 those = 7;
Expand Down Expand Up @@ -142,6 +145,7 @@ service RpcService {
rpc UnaryRpc ( Request ) returns ( google.protobuf.Empty ) {
/* trailer for method */

/* this RPC is deprecated! */
option deprecated = true;

option (testprotos.mtfubar) = 12.340000;
Expand Down
4 changes: 4 additions & 0 deletions desc/protoprint/testfiles/desc_test_comments-sorted.proto
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ message Request {

// can be these or those
oneof xyz {
// whoops?
option (testprotos.oofubar) = "whoops!";

string these = 6;

int32 those = 7;
Expand Down Expand Up @@ -123,6 +126,7 @@ service RpcService {
rpc UnaryRpc ( Request ) returns ( google.protobuf.Empty ) {
// trailer for method

// this RPC is deprecated!
option deprecated = true;

option (testprotos.mtfubar) = 12.340000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ message Request {

// can be these or those
oneof xyz {
// whoops?
option (testprotos.oofubar) = "whoops!";

string these = 6;

int32 those = 7;
Expand Down Expand Up @@ -157,6 +160,7 @@ service RpcService {
rpc UnaryRpc ( Request ) returns ( google.protobuf.Empty ) {
// trailer for method

// this RPC is deprecated!
option deprecated = true;

option (testprotos.mtfubar) = 12.340000;
Expand Down
3 changes: 3 additions & 0 deletions desc/protoprint/testfiles/test-non-files-compact.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ message Request {
}
// can be these or those
oneof xyz {
option (.testprotos.oofubar) = "whoops!";
string these = 6;
int32 those = 7;
}
Expand Down Expand Up @@ -100,6 +101,7 @@ message Request {
}
// can be these or those
oneof xyz {
option (.testprotos.oofubar) = "whoops!";
string these = 6;
int32 those = 7;
}
Expand Down Expand Up @@ -160,6 +162,7 @@ oneof abc {
}
-------- foo.bar.Request.xyz (*desc.OneOfDescriptor) --------
oneof xyz {
option (.testprotos.oofubar) = "whoops!";
string these = 6;
int32 those = 7;
}
Expand Down
11 changes: 11 additions & 0 deletions desc/protoprint/testfiles/test-non-files-full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ message /* detached message name */ /* request with a capital R */ Request /* tr

// can be these or those
oneof xyz {
// whoops?
option (testprotos.oofubar) = "whoops!";

string these = 6;

int32 those = 7;
Expand Down Expand Up @@ -157,6 +160,7 @@ service /* service name */ RpcService {
rpc UnaryRpc ( Request ) returns ( google.protobuf.Empty ) {
// trailer for method

// this RPC is deprecated!
option deprecated = true;

option (testprotos.mtfubar) = 12.340000;
Expand Down Expand Up @@ -260,6 +264,9 @@ message /* detached message name */ /* request with a capital R */ Request /* tr

// can be these or those
oneof xyz {
// whoops?
option (testprotos.oofubar) = "whoops!";

string these = 6;

int32 those = 7;
Expand Down Expand Up @@ -320,6 +327,8 @@ oneof abc {
}
-------- foo.bar.Request.xyz (*desc.OneOfDescriptor) --------
oneof xyz {
option (testprotos.oofubar) = "whoops!";

string these = 6;

int32 those = 7;
Expand Down Expand Up @@ -449,6 +458,7 @@ service /* service name */ RpcService {
rpc UnaryRpc ( Request ) returns ( google.protobuf.Empty ) {
// trailer for method

// this RPC is deprecated!
option deprecated = true;

option (testprotos.mtfubar) = 12.340000;
Expand All @@ -463,6 +473,7 @@ rpc /* rpc name */ StreamingRpc /* comment A */ ( /* comment C */ stream Request
rpc UnaryRpc ( Request ) returns ( google.protobuf.Empty ) {
// trailer for method

// this RPC is deprecated!
option deprecated = true;

option (testprotos.mtfubar) = 12.340000;
Expand Down
4 changes: 4 additions & 0 deletions desc/protoprint/testfiles/test-preserve-comments.proto
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ message /* detached message name */ /* request with a capital R */ Request /* tr

// can be these or those
oneof xyz {
// whoops?
option (testprotos.oofubar) = "whoops!";

string these = 6;

int32 those = 7;
Expand Down Expand Up @@ -156,6 +159,7 @@ service /* service name */ RpcService {
rpc UnaryRpc ( Request ) returns ( google.protobuf.Empty ) {
// trailer for method

// this RPC is deprecated!
option deprecated = true;

option (testprotos.mtfubar) = 12.340000;
Expand Down
2 changes: 2 additions & 0 deletions desc/protoprint/testfiles/test-preserve-doc-comments.proto
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ message Request {

// can be these or those
oneof xyz {
option (testprotos.oofubar) = "whoops!";

string these = 6;

int32 those = 7;
Expand Down
7 changes: 1 addition & 6 deletions internal/testprotos/desc_test1.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions internal/testprotos/desc_test2.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0e352eb

Please sign in to comment.