Inline comments not parsed on RPCs if they end with {}
bufdev opened this issue · comments
bufdev commented
TestService
in service_test.go
edited as such:
func TestService(t *testing.T) {
proto := `service AccountService {
// comment
rpc CreateAccount (CreateAccount) returns (ServiceFault); // inline comment
rpc GetAccounts (stream Int64) returns (Account) {} // inline comment2
rpc Health(google.protobuf.Empty) returns (google.protobuf.Empty) {} // inline comment3
}`
pr, err := newParserOn(proto).Parse()
if err != nil {
t.Fatal(err)
}
srv := collect(pr).Services()[0]
if got, want := len(srv.Elements), 3; got != want {
t.Fatalf("got [%v] want [%v]", got, want)
}
if got, want := srv.Position.String(), "<input>:1:1"; got != want {
t.Fatalf("got [%v] want [%v]", got, want)
}
rpc1 := srv.Elements[0].(*RPC)
if got, want := rpc1.Name, "CreateAccount"; got != want {
t.Fatalf("got [%v] want [%v]", got, want)
}
if got, want := rpc1.Doc().Message(), " comment"; got != want {
t.Fatalf("got [%v] want [%v]", got, want)
}
if got, want := rpc1.InlineComment.Message(), " inline comment"; got != want {
t.Fatalf("got [%v] want [%v]", got, want)
}
if got, want := rpc1.Position.Line, 3; got != want {
t.Fatalf("got [%v] want [%v]", got, want)
}
rpc2 := srv.Elements[1].(*RPC)
if got, want := rpc2.Name, "GetAccounts"; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
rpc3 := srv.Elements[2].(*RPC)
if got, want := rpc3.Name, "Health"; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
if got, want := rpc2.InlineComment.Message(), " inline comment2"; got != want {
t.Fatalf("got [%v] want [%v]", got, want)
}
if got, want := rpc3.InlineComment.Message(), " inline comment3"; got != want {
t.Fatalf("got [%v] want [%v]", got, want)
}
}
inline comments 2 and 3 are not associated with the relevant RPCs.
bufdev commented
The issue is that Service.parse
and RPC.parse
treat tSEMICOLON
differently than tRIGHTCURLY
- I'm still getting familiar with the code but I think there's an issue here, let me know if you figure it out.
Ernest Micklei commented
yes the inline comment handling needs a global review and refactoring.