From 2e6fbd84f8b884c6fc8b95a633f289c0df1f1bf8 Mon Sep 17 00:00:00 2001 From: Andrew Gerrand Date: Wed, 28 Aug 2013 09:39:02 +1000 Subject: [PATCH] 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 --- cmd/godoc/main.go | 2 +- godoc/server.go | 29 ++++++++++++++++++++++------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/cmd/godoc/main.go b/cmd/godoc/main.go index eb1217a8..63cdcbfb 100644 --- a/cmd/godoc/main.go +++ b/cmd/godoc/main.go @@ -359,7 +359,7 @@ func main() { var mode godoc.PageInfoMode if relpath == "builtin" { // the fake built-in package contains unexported identifiers - mode = godoc.NoFiltering + mode = godoc.NoFiltering | godoc.NoFactoryFuncs } if *srcMode { // only filter exports if we don't have explicit command-line filter arguments diff --git a/godoc/server.go b/godoc/server.go index 9744a504..95f43979 100644 --- a/godoc/server.go +++ b/godoc/server.go @@ -19,6 +19,7 @@ import ( "os" pathpkg "path" "path/filepath" + "sort" "strings" "text/template" "time" @@ -110,12 +111,19 @@ func (h *handlerServer) GetPageInfo(abspath, relpath string, mode PageInfoMode) // show extracted documentation var m doc.Mode if mode&NoFiltering != 0 { - m = doc.AllDecls + m |= doc.AllDecls } if mode&AllMethods != 0 { m |= doc.AllMethods } 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 testfiles := append(pkginfo.TestGoFiles, pkginfo.XTestGoFiles...) @@ -177,6 +185,12 @@ func (h *handlerServer) GetPageInfo(abspath, relpath string, mode PageInfoMode) 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) { if redirect(w, r) { return @@ -186,7 +200,7 @@ func (h *handlerServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { abspath := pathpkg.Join(h.fsRoot, relpath) mode := h.p.GetPageInfoMode(r) if relpath == builtinPkgPath { - mode = NoFiltering + mode = NoFiltering | NoFactoryFuncs } info := h.GetPageInfo(abspath, relpath, mode) if info.Err != nil { @@ -243,11 +257,12 @@ func (h *handlerServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { type PageInfoMode uint const ( - NoFiltering PageInfoMode = 1 << iota // do not filter exports - AllMethods // show all embedded methods - ShowSource // show source code, do not extract documentation - NoHTML // show result in textual form, do not generate HTML - FlatDir // show directory in a flat (non-indented) manner + NoFiltering PageInfoMode = 1 << iota // do not filter exports + AllMethods // show all embedded methods + ShowSource // show source code, do not extract documentation + NoHTML // show result in textual form, do not generate HTML + 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.