mirror of
https://github.com/golang/go
synced 2024-11-23 14:30:02 -07:00
cmd/doc: show variables of unexported types for -all
We use the typedValue map to prevent showing typed variables and constants from appearing in the VARIABLES/CONSTANTS section because they will be anyways shown in the TYPES section for that type. However, when a type is unexported, but the variable is exported, then unconditionally setting it to true in the map suppresses it from being shown in the VARIABLES section. Thus, we set the variable or constant in the typedValue map only when the type name is exported. Fixes #31067 Change-Id: Id3ec4b313c9ea7e3ce6fe279680d56f65451719f Reviewed-on: https://go-review.googlesource.com/c/go/+/206129 Run-TryBot: Agniva De Sarker <agniva.quicksilver@gmail.com> Reviewed-by: Rob Pike <r@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
c2edcf4b12
commit
72e043e48b
@ -176,6 +176,7 @@ var tests = []test{
|
||||
`Comment about block of variables`,
|
||||
`VarFive = 5`,
|
||||
`var ExportedVariable = 1`,
|
||||
`var ExportedVarOfUnExported unexportedType`,
|
||||
`var LongLine = newLongLine\(`,
|
||||
`var MultiLineVar = map\[struct {`,
|
||||
`FUNCTIONS`,
|
||||
|
@ -172,18 +172,18 @@ func parsePackage(writer io.Writer, pkg *build.Package, userPath string) *Packag
|
||||
constructor := make(map[*doc.Func]bool)
|
||||
for _, typ := range docPkg.Types {
|
||||
docPkg.Consts = append(docPkg.Consts, typ.Consts...)
|
||||
for _, value := range typ.Consts {
|
||||
typedValue[value] = true
|
||||
}
|
||||
docPkg.Vars = append(docPkg.Vars, typ.Vars...)
|
||||
for _, value := range typ.Vars {
|
||||
typedValue[value] = true
|
||||
}
|
||||
docPkg.Funcs = append(docPkg.Funcs, typ.Funcs...)
|
||||
for _, fun := range typ.Funcs {
|
||||
// We don't count it as a constructor bound to the type
|
||||
// if the type itself is not exported.
|
||||
if isExported(typ.Name) {
|
||||
if isExported(typ.Name) {
|
||||
for _, value := range typ.Consts {
|
||||
typedValue[value] = true
|
||||
}
|
||||
for _, value := range typ.Vars {
|
||||
typedValue[value] = true
|
||||
}
|
||||
for _, fun := range typ.Funcs {
|
||||
// We don't count it as a constructor bound to the type
|
||||
// if the type itself is not exported.
|
||||
constructor[fun] = true
|
||||
}
|
||||
}
|
||||
|
2
src/cmd/doc/testdata/pkg.go
vendored
2
src/cmd/doc/testdata/pkg.go
vendored
@ -35,6 +35,8 @@ const (
|
||||
// Comment about exported variable.
|
||||
var ExportedVariable = 1
|
||||
|
||||
var ExportedVarOfUnExported unexportedType
|
||||
|
||||
// Comment about internal variable.
|
||||
var internalVariable = 2
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user