go.tools/godoc: don't associate builtin nil with a type
Special case for (fake) package builtin: don't associate any constant, variable, or factory function with a type. Fixes golang/go#6645. LGTM=bgarcia R=bgarcia, r, bradfitz CC=golang-codereviews https://golang.org/cl/54820044
This commit is contained in:
parent
20efc5ba73
commit
5351a1ccd2
|
@ -43,9 +43,9 @@ func CommandLine(w io.Writer, fs vfs.NameSpace, pres *Presentation, args []strin
|
||||||
}
|
}
|
||||||
|
|
||||||
var mode PageInfoMode
|
var mode PageInfoMode
|
||||||
if relpath == "builtin" {
|
if relpath == builtinPkgPath {
|
||||||
// the fake built-in package contains unexported identifiers
|
// the fake built-in package contains unexported identifiers
|
||||||
mode = NoFiltering | NoFactoryFuncs
|
mode = NoFiltering | NoTypeAssoc
|
||||||
}
|
}
|
||||||
if srcMode {
|
if srcMode {
|
||||||
// only filter exports if we don't have explicit command-line filter arguments
|
// only filter exports if we don't have explicit command-line filter arguments
|
||||||
|
|
|
@ -118,11 +118,17 @@ func (h *handlerServer) GetPageInfo(abspath, relpath string, mode PageInfoMode)
|
||||||
m |= doc.AllMethods
|
m |= doc.AllMethods
|
||||||
}
|
}
|
||||||
info.PDoc = doc.New(pkg, pathpkg.Clean(relpath), m) // no trailing '/' in importpath
|
info.PDoc = doc.New(pkg, pathpkg.Clean(relpath), m) // no trailing '/' in importpath
|
||||||
if mode&NoFactoryFuncs != 0 {
|
if mode&NoTypeAssoc != 0 {
|
||||||
for _, t := range info.PDoc.Types {
|
for _, t := range info.PDoc.Types {
|
||||||
|
info.PDoc.Consts = append(info.PDoc.Consts, t.Consts...)
|
||||||
|
info.PDoc.Vars = append(info.PDoc.Vars, t.Vars...)
|
||||||
info.PDoc.Funcs = append(info.PDoc.Funcs, t.Funcs...)
|
info.PDoc.Funcs = append(info.PDoc.Funcs, t.Funcs...)
|
||||||
|
t.Consts = nil
|
||||||
|
t.Vars = nil
|
||||||
t.Funcs = nil
|
t.Funcs = nil
|
||||||
}
|
}
|
||||||
|
// for now we cannot easily sort consts and vars since
|
||||||
|
// go/doc.Value doesn't export the order information
|
||||||
sort.Sort(funcsByName(info.PDoc.Funcs))
|
sort.Sort(funcsByName(info.PDoc.Funcs))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,7 +207,7 @@ func (h *handlerServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
abspath := pathpkg.Join(h.fsRoot, relpath)
|
abspath := pathpkg.Join(h.fsRoot, relpath)
|
||||||
mode := h.p.GetPageInfoMode(r)
|
mode := h.p.GetPageInfoMode(r)
|
||||||
if relpath == builtinPkgPath {
|
if relpath == builtinPkgPath {
|
||||||
mode = NoFiltering | NoFactoryFuncs
|
mode = NoFiltering | NoTypeAssoc
|
||||||
}
|
}
|
||||||
info := h.GetPageInfo(abspath, relpath, mode)
|
info := h.GetPageInfo(abspath, relpath, mode)
|
||||||
if info.Err != nil {
|
if info.Err != nil {
|
||||||
|
@ -261,12 +267,12 @@ func (h *handlerServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
type PageInfoMode uint
|
type PageInfoMode uint
|
||||||
|
|
||||||
const (
|
const (
|
||||||
NoFiltering PageInfoMode = 1 << iota // do not filter exports
|
NoFiltering PageInfoMode = 1 << iota // do not filter exports
|
||||||
AllMethods // show all embedded methods
|
AllMethods // show all embedded methods
|
||||||
ShowSource // show source code, do not extract documentation
|
ShowSource // show source code, do not extract documentation
|
||||||
NoHTML // show result in textual form, do not generate HTML
|
NoHTML // show result in textual form, do not generate HTML
|
||||||
FlatDir // show directory in a flat (non-indented) manner
|
FlatDir // show directory in a flat (non-indented) manner
|
||||||
NoFactoryFuncs // don't associate factory functions with their result types
|
NoTypeAssoc // don't associate consts, vars, and factory functions with types
|
||||||
)
|
)
|
||||||
|
|
||||||
// modeNames defines names for each PageInfoMode flag.
|
// modeNames defines names for each PageInfoMode flag.
|
||||||
|
|
Loading…
Reference in New Issue