Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
silves-xiang committed May 20, 2024
1 parent 4a1e29d commit 2ff0ad2
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions cmd/protoc-gen-go-grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ func generateFileContent(gen *protogen.Plugin, file *protogen.File, g *protogen.
}
}

func copyCommentsFromProto(g *protogen.GeneratedFile, service *protogen.Service) {
// add line for vscode dosn't display top of comment
g.P()
// print comment without '\n', if comment has '\n', vscode dosn't display it
g.P(strings.TrimSpace(service.Comments.Leading.String()))
}

func genService(gen *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFile, service *protogen.Service) {
// Full methods constants.
helper.genFullMethods(g, service)
Expand All @@ -197,9 +204,9 @@ func genService(gen *protogen.Plugin, file *protogen.File, g *protogen.Generated
g.P("// ", clientName, " is the client API for ", service.GoName, " service.")
g.P("//")
g.P("// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.")
g.P() // for vscode dosn't display top of comment
// print comment without '\n', if comment has '\n', vscode dosn't display it
g.P(strings.TrimSpace(service.Comments.Leading.String()))

// copy comments from proto file
copyCommentsFromProto(g, service)

if service.Desc.Options().(*descriptorpb.ServiceOptions).GetDeprecated() {
g.P("//")
Expand Down Expand Up @@ -254,9 +261,9 @@ func genService(gen *protogen.Plugin, file *protogen.File, g *protogen.Generated
g.P("// ", serverType, " is the server API for ", service.GoName, " service.")
g.P("// All implementations ", mustOrShould, " embed Unimplemented", serverType)
g.P("// for forward compatibility")
g.P() // for vscode dosn't display top of comment
// print comment without '\n', if comment has '\n', vscode dosn't display it
g.P(strings.TrimSpace(service.Comments.Leading.String()))

// copy comments from proto file
copyCommentsFromProto(g, service)

if service.Desc.Options().(*descriptorpb.ServiceOptions).GetDeprecated() {
g.P("//")
Expand Down

0 comments on commit 2ff0ad2

Please sign in to comment.