From 9394956cfdc50651347ab69dbde09af8a8e24776 Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Mon, 18 Feb 2019 13:49:49 -0500 Subject: [PATCH] godoc: don't clear user-set page mode for package builtin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When rendering the documentation of the fake package builtin, there are two PageInfoMode flags that always get set, regardless of what the user has provided via the ?m= query parameter. They are: • NoFiltering • NoTypeAssoc This is being done to make the documention of this special package more usable and helpful (see golang/go#6645). This change modifies the way those flags are set, so that any additional flags the user may have set are no longer cleared. This makes it possible, for example, to use ?m=src to view the source, as it is for all other packages. Also elaborate more about this behavior in the comments. Fixes golang/go#30300 Updates golang/go#6645 Change-Id: I77728bd2683191b97d8f58f19092f2833dfc474c Reviewed-on: https://go-review.googlesource.com/c/162983 Reviewed-by: Brad Fitzpatrick --- godoc/godoc.go | 4 +++- godoc/server.go | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/godoc/godoc.go b/godoc/godoc.go index 86575f60..0681a5ad 100644 --- a/godoc/godoc.go +++ b/godoc/godoc.go @@ -33,7 +33,9 @@ import ( ) // Fake relative package path for built-ins. Documentation for all globals -// (not just exported ones) will be shown for packages in this directory. +// (not just exported ones) will be shown for packages in this directory, +// and there will be no association of consts, vars, and factory functions +// with types (see issue 6645). const builtinPkgPath = "builtin" // FuncMap defines template functions used in godoc templates. diff --git a/godoc/server.go b/godoc/server.go index b03e14a6..693599b4 100644 --- a/godoc/server.go +++ b/godoc/server.go @@ -268,7 +268,10 @@ 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 | NoTypeAssoc + // The fake built-in package contains unexported identifiers, + // but we want to show them. Also, disable type association, + // since it's not helpful for this fake package (see issue 6645). + mode |= NoFiltering | NoTypeAssoc } info := h.GetPageInfo(abspath, relpath, mode, r.FormValue("GOOS"), r.FormValue("GOARCH")) if info.Err != nil { @@ -357,7 +360,7 @@ const ( AllMethods // show all embedded methods ShowSource // show source code, do not extract documentation FlatDir // show directory in a flat (non-indented) manner - NoTypeAssoc // don't associate consts, vars, and factory functions with types + NoTypeAssoc // don't associate consts, vars, and factory functions with types (not exposed via ?m= query parameter, used for package builtin, see issue 6645) ) // modeNames defines names for each PageInfoMode flag.