Skip to content

Commit

Permalink
Only generate imports in GenerateImports,
Browse files Browse the repository at this point in the history
and move the `var _ pkg.Blah` lines to Generate time.

This helps in the case of multiple plugins.

Fixes #57.
  • Loading branch information
dsymonds committed Aug 10, 2015
1 parent 68c687d commit 73aaaa9
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions protoc-gen-go/internal/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ func (g *grpc) P(args ...interface{}) { g.gen.P(args...) }

// Generate generates code for the services in the given file.
func (g *grpc) Generate(file *generator.FileDescriptor) {
if len(file.FileDescriptorProto.Service) == 0 {
return
}
g.P("// Reference imports to suppress errors if they are not otherwise used.")
g.P("var _ ", contextPkg, ".Context")
g.P("var _ ", grpcPkg, ".ClientConn")
g.P()
for i, service := range file.FileDescriptorProto.Service {
g.generateService(file, service, i)
}
Expand All @@ -113,10 +120,6 @@ func (g *grpc) GenerateImports(file *generator.FileDescriptor) {
g.P(grpcPkg, " ", strconv.Quote(path.Join(g.gen.ImportPrefix, grpcPkgPath)))
g.P(")")
g.P()
g.P("// Reference imports to suppress errors if they are not otherwise used.")
g.P("var _ ", contextPkg, ".Context")
g.P("var _ ", grpcPkg, ".ClientConn")
g.P()
}

// reservedClientName records whether a client name is reserved on the client side.
Expand Down

0 comments on commit 73aaaa9

Please sign in to comment.