mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/doc: do not show unexported constants
The go/doc package doesn't remove unexported entries from const and var blocks, so we must trim them ourselves. Fixes #11008 Change-Id: Ibd60d87e09333964e2588340a2ca2b8804bbaa28 Reviewed-on: https://go-review.googlesource.com/10643 Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
parent
a7d2d4835b
commit
ea92f42cc8
1 changed files with 19 additions and 0 deletions
|
|
@ -332,6 +332,25 @@ func (pkg *Package) symbolDoc(symbol string) {
|
|||
values := pkg.findValues(symbol, pkg.doc.Consts)
|
||||
values = append(values, pkg.findValues(symbol, pkg.doc.Vars)...)
|
||||
for _, value := range values {
|
||||
// Print each spec only if there is at least one exported symbol in it.
|
||||
// (See issue 11008.)
|
||||
// TODO: Should we elide unexported symbols from a single spec?
|
||||
// It's an unlikely scenario, probably not worth the trouble.
|
||||
// TODO: Would be nice if go/doc did this for us.
|
||||
specs := make([]ast.Spec, 0, len(value.Decl.Specs))
|
||||
for _, spec := range value.Decl.Specs {
|
||||
vspec := spec.(*ast.ValueSpec)
|
||||
for _, ident := range vspec.Names {
|
||||
if isExported(ident.Name) {
|
||||
specs = append(specs, vspec)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(specs) == 0 {
|
||||
continue
|
||||
}
|
||||
value.Decl.Specs = specs
|
||||
if !found {
|
||||
pkg.packageClause(true)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue