godoc: don't clear user-set page mode for package builtin

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 <bradfitz@golang.org>
This commit is contained in:
Dmitri Shuralyov 2019-02-18 13:49:49 -05:00
Родитель d38dac729d
Коммит 9394956cfd
2 изменённых файлов: 8 добавлений и 3 удалений

Просмотреть файл

@ -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.

Просмотреть файл

@ -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.