cmd/doc: implement "go doc struct.field"

By analogy with the handling of methods on types, show the documentation
for a single field of a struct.

	% go doc ast.structtype.fields
	struct StructType {
	    Fields *FieldList  // list of field declarations
	}
	%

Fixes #19169.

Change-Id: I002f992e4aa64bee667e2e4bccc7082486149842
Reviewed-on: https://go-review.googlesource.com/38438
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Rob Pike 2017-03-21 20:27:47 -07:00
parent 19040ac871
commit 2c47c3e22e
5 changed files with 112 additions and 29 deletions

View file

@ -390,6 +390,29 @@ var tests = []test{
nil,
},
// Field.
{
"field",
[]string{p, `ExportedType.ExportedField`},
[]string{
`ExportedField int`,
`Comment before exported field.`,
`Comment on line with exported field.`,
},
nil,
},
// Field with -u.
{
"method with -u",
[]string{"-u", p, `ExportedType.unexportedField`},
[]string{
`unexportedField int`,
`Comment on line with unexported field.`,
},
nil,
},
// Case matching off.
{
"case matching off",