go.tools/cmd/godoc: don't list factory functions under types in builtin package

Fixes golang/go#6220.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/13094049
This commit is contained in:
Andrew Gerrand 2013-08-28 09:39:02 +10:00
parent 713699d8ad
commit 2e6fbd84f8
2 changed files with 23 additions and 8 deletions

View File

@ -359,7 +359,7 @@ func main() {
var mode godoc.PageInfoMode var mode godoc.PageInfoMode
if relpath == "builtin" { if relpath == "builtin" {
// the fake built-in package contains unexported identifiers // the fake built-in package contains unexported identifiers
mode = godoc.NoFiltering mode = godoc.NoFiltering | godoc.NoFactoryFuncs
} }
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

View File

@ -19,6 +19,7 @@ import (
"os" "os"
pathpkg "path" pathpkg "path"
"path/filepath" "path/filepath"
"sort"
"strings" "strings"
"text/template" "text/template"
"time" "time"
@ -110,12 +111,19 @@ func (h *handlerServer) GetPageInfo(abspath, relpath string, mode PageInfoMode)
// show extracted documentation // show extracted documentation
var m doc.Mode var m doc.Mode
if mode&NoFiltering != 0 { if mode&NoFiltering != 0 {
m = doc.AllDecls m |= doc.AllDecls
} }
if mode&AllMethods != 0 { if mode&AllMethods != 0 {
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 {
for _, t := range info.PDoc.Types {
info.PDoc.Funcs = append(info.PDoc.Funcs, t.Funcs...)
t.Funcs = nil
}
sort.Sort(funcsByName(info.PDoc.Funcs))
}
// collect examples // collect examples
testfiles := append(pkginfo.TestGoFiles, pkginfo.XTestGoFiles...) testfiles := append(pkginfo.TestGoFiles, pkginfo.XTestGoFiles...)
@ -177,6 +185,12 @@ func (h *handlerServer) GetPageInfo(abspath, relpath string, mode PageInfoMode)
return info return info
} }
type funcsByName []*doc.Func
func (s funcsByName) Len() int { return len(s) }
func (s funcsByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s funcsByName) Less(i, j int) bool { return s[i].Name < s[j].Name }
func (h *handlerServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (h *handlerServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if redirect(w, r) { if redirect(w, r) {
return return
@ -186,7 +200,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 mode = NoFiltering | NoFactoryFuncs
} }
info := h.GetPageInfo(abspath, relpath, mode) info := h.GetPageInfo(abspath, relpath, mode)
if info.Err != nil { if info.Err != nil {
@ -248,6 +262,7 @@ const (
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
) )
// modeNames defines names for each PageInfoMode flag. // modeNames defines names for each PageInfoMode flag.