diff options
author | David Symonds <dsymonds@golang.org> | 2014-01-13 16:01:41 +1100 |
---|---|---|
committer | David Symonds <dsymonds@golang.org> | 2014-01-13 16:01:41 +1100 |
commit | 7d640deeae4593729f12f200f0b7e1357d0c15be (patch) | |
tree | cc585afc7c76c16fffc1f54ce10ce11359228ccb | |
parent | 1d8ba13d546b838c0d562d116c4fabc3094b23a7 (diff) | |
download | protobuf-7d640deeae4593729f12f200f0b7e1357d0c15be.tar.gz |
goprotobuf: Generate package docs.
Most people won't see these, but they improve how proto packages are rendered by godoc.
R=r
CC=golang-codereviews
https://codereview.appspot.com/51030043
-rw-r--r-- | proto/testdata/test.pb.go | 32 | ||||
-rw-r--r-- | protoc-gen-go/descriptor/descriptor.pb.go | 25 | ||||
-rw-r--r-- | protoc-gen-go/generator/generator.go | 30 | ||||
-rw-r--r-- | protoc-gen-go/plugin/plugin.pb.go | 10 | ||||
-rw-r--r-- | protoc-gen-go/testdata/my_test/test.pb.go | 12 | ||||
-rw-r--r-- | protoc-gen-go/testdata/my_test/test.pb.go.golden | 12 |
6 files changed, 119 insertions, 2 deletions
diff --git a/proto/testdata/test.pb.go b/proto/testdata/test.pb.go index eb3f65a..f48a04e 100644 --- a/proto/testdata/test.pb.go +++ b/proto/testdata/test.pb.go @@ -2,6 +2,38 @@ // source: test.proto // DO NOT EDIT! +/* +Package testdata is a generated protocol buffer package. + +It is generated from these files: + test.proto + +It has these top-level messages: + GoEnum + GoTestField + GoTest + GoSkipTest + NonPackedTest + PackedTest + MaxTag + OldMessage + NewMessage + InnerMessage + OtherMessage + MyMessage + Ext + MyMessageSet + Empty + MessageList + Strings + Defaults + SubDefaults + RepeatedEnum + MoreRepeated + GroupOld + GroupNew + FloatingPoint +*/ package testdata import proto "code.google.com/p/goprotobuf/proto" diff --git a/protoc-gen-go/descriptor/descriptor.pb.go b/protoc-gen-go/descriptor/descriptor.pb.go index a48174f..5f859be 100644 --- a/protoc-gen-go/descriptor/descriptor.pb.go +++ b/protoc-gen-go/descriptor/descriptor.pb.go @@ -2,6 +2,31 @@ // source: google/protobuf/descriptor.proto // DO NOT EDIT! +/* +Package google_protobuf is a generated protocol buffer package. + +It is generated from these files: + google/protobuf/descriptor.proto + +It has these top-level messages: + FileDescriptorSet + FileDescriptorProto + DescriptorProto + FieldDescriptorProto + EnumDescriptorProto + EnumValueDescriptorProto + ServiceDescriptorProto + MethodDescriptorProto + FileOptions + MessageOptions + FieldOptions + EnumOptions + EnumValueOptions + ServiceOptions + MethodOptions + UninterpretedOption + SourceCodeInfo +*/ package google_protobuf import proto "code.google.com/p/goprotobuf/proto" diff --git a/protoc-gen-go/generator/generator.go b/protoc-gen-go/generator/generator.go index 9f38cad..160e1db 100644 --- a/protoc-gen-go/generator/generator.go +++ b/protoc-gen-go/generator/generator.go @@ -239,6 +239,8 @@ type FileDescriptor struct { // as a map from the exported object to its symbols. // This is used for supporting public imports. exported map[Object][]symbol + + index int // The index of this file in the list of files to generate code for } // PackageName is the package name we'll use in the generated code to refer to this file. @@ -673,6 +675,7 @@ FindFiles: for _, file := range g.allFiles { if fileName == file.GetName() { g.genFiles[i] = file + file.index = i continue FindFiles } } @@ -1028,10 +1031,33 @@ func (g *Generator) generate(file *FileDescriptor) { // Generate the header, including package definition func (g *Generator) generateHeader() { g.P("// Code generated by protoc-gen-go.") - g.P("// source: ", *g.file.Name) + g.P("// source: ", g.file.Name) g.P("// DO NOT EDIT!") g.P() - g.P("package ", g.file.PackageName()) + + name := g.file.PackageName() + + if g.file.index == 0 { + // Generate package docs for the first file in the package. + g.P("/*") + g.P("Package ", name, " is a generated protocol buffer package.") + g.P() + g.P("It is generated from these files:") + for _, f := range g.genFiles { + g.P("\t", f.Name) + } + g.P() + g.P("It has these top-level messages:") + for _, msg := range g.file.desc { + if msg.parent != nil { + continue + } + g.P("\t", CamelCaseSlice(msg.TypeName())) + } + g.P("*/") + } + + g.P("package ", name) g.P() } diff --git a/protoc-gen-go/plugin/plugin.pb.go b/protoc-gen-go/plugin/plugin.pb.go index 90e90ce..7ffd98c 100644 --- a/protoc-gen-go/plugin/plugin.pb.go +++ b/protoc-gen-go/plugin/plugin.pb.go @@ -2,6 +2,16 @@ // source: google/protobuf/compiler/plugin.proto // DO NOT EDIT! +/* +Package google_protobuf_compiler is a generated protocol buffer package. + +It is generated from these files: + google/protobuf/compiler/plugin.proto + +It has these top-level messages: + CodeGeneratorRequest + CodeGeneratorResponse +*/ package google_protobuf_compiler import proto "code.google.com/p/goprotobuf/proto" diff --git a/protoc-gen-go/testdata/my_test/test.pb.go b/protoc-gen-go/testdata/my_test/test.pb.go index 12abf2b..9f561f2 100644 --- a/protoc-gen-go/testdata/my_test/test.pb.go +++ b/protoc-gen-go/testdata/my_test/test.pb.go @@ -2,6 +2,18 @@ // source: my_test/test.proto // DO NOT EDIT! +/* +Package my_test is a generated protocol buffer package. + +It is generated from these files: + my_test/test.proto + +It has these top-level messages: + Request + Reply + ReplyExtensions + OldReply +*/ package my_test import proto "code.google.com/p/goprotobuf/proto" diff --git a/protoc-gen-go/testdata/my_test/test.pb.go.golden b/protoc-gen-go/testdata/my_test/test.pb.go.golden index 12abf2b..9f561f2 100644 --- a/protoc-gen-go/testdata/my_test/test.pb.go.golden +++ b/protoc-gen-go/testdata/my_test/test.pb.go.golden @@ -2,6 +2,18 @@ // source: my_test/test.proto // DO NOT EDIT! +/* +Package my_test is a generated protocol buffer package. + +It is generated from these files: + my_test/test.proto + +It has these top-level messages: + Request + Reply + ReplyExtensions + OldReply +*/ package my_test import proto "code.google.com/p/goprotobuf/proto" |