golang / protobuf

Go support for Google's protocol buffers
BSD 3-Clause "New" or "Revised" License
9.8k stars 1.58k forks source link

err comment output in generated file by protoc-gen-go #1654

Closed yangjuncode closed 1 month ago

yangjuncode commented 1 month ago

What version of protobuf and what language are you using? // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.34.2 // protoc v5.28.1 // source: test.proto

What did you do? protoc --go_out=. test.proto

What did you expect to see? keep the original comment in generated go file

What did you see instead? the ''(two char) in proto file become ”(one char) in generated go file

test.tar.gz

puellanivis commented 1 month ago

I am not understanding what your issue here is. I have downloaded your test.tar.gz and compiled with protoc-gen-go@v1.34.2 and the only thing that changed in the comment is that protoc is now reflects the version of protoc that I have installed on my system.

There is no reason why the original comment should be kept, if the .pb.go file is generated with a different version of protoc or protoc-gen-go. That’s literally the purpose of the comments: to document the versions it was generated through.

yangjuncode commented 1 month ago

I am not understanding what your issue here is. I have downloaded your test.tar.gz and compiled with protoc-gen-go@v1.34.2 and the only thing that changed in the comment is that protoc is now reflects the version of protoc that I have installed on my system.

There is no reason why the original comment should be kept, if the .pb.go file is generated with a different version of protoc or protoc-gen-go. That’s literally the purpose of the comments: to document the versions it was generated through.

the problem is show in screenshot, in proto there is ''(two char), in generated pb.go file, it's ”(one char). 2024-10-26_09-43

puellanivis commented 1 month ago

We’re calling into go/doc/comment/Parser here: https://github.com/golang/go/blob/master/src/go/printer/comment.go#L61-L63

This converts double backtick to and double apostrophe to here: https://github.com/golang/go/blob/master/src/go/doc/comment/parse.go#L942-L960

This is apparently a feature, not a bug?

P.S.: minimal repro on playground: https://go.dev/play/p/hR2WLK26fIo

yangjuncode commented 1 month ago

oops, well it's a feature of go doc, but it's a surprise for proto user