aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/doc/pkg.go
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2017-07-06 20:02:26 +0000
committerBrad Fitzpatrick <bradfitz@golang.org>2017-07-06 21:57:52 +0000
commit39ed6b14b4212008e32bb53e87fd46d4faa13ce2 (patch)
treebef2afb48c1bdf358fd57f46bcada30cb0427bd9 /src/cmd/doc/pkg.go
parentd1340ee2e91a873d689cf11b74022f60476cd729 (diff)
downloadgo-39ed6b14b4212008e32bb53e87fd46d4faa13ce2.tar.xz
cmd/doc: print Go syntax when printing struct.field docs
Fixes #20928 Change-Id: I7f7aafb8ff4b5deb50c286a9ae81c34ee85e56a9 Reviewed-on: https://go-review.googlesource.com/47730 Reviewed-by: Rob Pike <r@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/cmd/doc/pkg.go')
-rw-r--r--src/cmd/doc/pkg.go36
1 files changed, 21 insertions, 15 deletions
diff --git a/src/cmd/doc/pkg.go b/src/cmd/doc/pkg.go
index 7b0f9de775..5a14d6e7cf 100644
--- a/src/cmd/doc/pkg.go
+++ b/src/cmd/doc/pkg.go
@@ -833,6 +833,7 @@ func (pkg *Package) printFieldDoc(symbol, fieldName string) bool {
pkg.Fatalf("symbol %s is not a type in package %s installed in %q", symbol, pkg.name, pkg.build.ImportPath)
}
found := false
+ numUnmatched := 0
for _, typ := range types {
// Type must be a struct.
spec := pkg.findTypeSpec(typ.Decl, typ.Name)
@@ -844,27 +845,32 @@ func (pkg *Package) printFieldDoc(symbol, fieldName string) bool {
for _, field := range structType.Fields.List {
// TODO: Anonymous fields.
for _, name := range field.Names {
- if match(fieldName, name.Name) {
- if !found {
- pkg.Printf("struct %s {\n", typ.Name)
- }
- if field.Doc != nil {
- for _, comment := range field.Doc.List {
- doc.ToText(&pkg.buf, comment.Text, indent, indent, indentedWidth)
- }
- }
- s := pkg.oneLineNode(field.Type)
- lineComment := ""
- if field.Comment != nil {
- lineComment = fmt.Sprintf(" %s", field.Comment.List[0].Text)
+ if !match(fieldName, name.Name) {
+ numUnmatched++
+ continue
+ }
+ if !found {
+ pkg.Printf("type %s struct {\n", typ.Name)
+ }
+ if field.Doc != nil {
+ for _, comment := range field.Doc.List {
+ doc.ToText(&pkg.buf, comment.Text, indent, indent, indentedWidth)
}
- pkg.Printf("%s%s %s%s\n", indent, name, s, lineComment)
- found = true
}
+ s := pkg.oneLineNode(field.Type)
+ lineComment := ""
+ if field.Comment != nil {
+ lineComment = fmt.Sprintf(" %s", field.Comment.List[0].Text)
+ }
+ pkg.Printf("%s%s %s%s\n", indent, name, s, lineComment)
+ found = true
}
}
}
if found {
+ if numUnmatched > 0 {
+ pkg.Printf("\n // ... other fields elided ...\n")
+ }
pkg.Printf("}\n")
}
return found