Go: x/tools/cmd/godoc: show internal packages when explicitly requested

Created on 10 Aug 2015  路  5Comments  路  Source: golang/go

godoc's HTTP viewer by default appears to hide internal/ directories. For example, neither of these views give a hint that net/internal/socktest exists:

But sometimes it's nice to be able to look at the internals of a package that you're working on. (In particular, if there are a few internal packages, it's nice to see a list.) However, godoc continues to deny the existence of net/internal/ even when it's explicitly requested:

Instead you must already know exactly what you're looking for to be able to see it.

Can/should godoc be changed to show internal packages when an internal directory is explicitly requested, as in the /pkg/net/internal/ case above?

Tools

Most helpful comment

You can see them with http://tip.golang.org/pkg/?m=all

I think it makes sense to hide these on golang.org, but probably not for most general godoc instances.

It was issue #8879 that had them removed.

All 5 comments

You can see them with http://tip.golang.org/pkg/?m=all

I think it makes sense to hide these on golang.org, but probably not for most general godoc instances.

It was issue #8879 that had them removed.

Thanks for the tip, that's great to know. It's not very discoverable though, so it would be nice if it were automatic when I've explicitly navigated to an internal/ directory. And yes, maybe good to make it the default outside of golang.org.

What about adding a flag for setting the default PageInfoMode?

As an example:

diff --git a/cmd/godoc/main.go b/cmd/godoc/main.go
index 48a658e0..a1350596 100644
--- a/cmd/godoc/main.go
+++ b/cmd/godoc/main.go
@@ -290,6 +290,7 @@ func main() {
    pres.ShowTimestamps = *showTimestamps
    pres.ShowPlayground = *showPlayground
    pres.DeclLinks = *declLinks
+   pres.Mode = godoc.NoFiltering
    if *notesRx != "" {
        pres.NotesRx = regexp.MustCompile(*notesRx)
    }
diff --git a/godoc/pres.go b/godoc/pres.go
index 1daa5a12..3a7f4490 100644
--- a/godoc/pres.go
+++ b/godoc/pres.go
@@ -46,6 +46,7 @@ type Presentation struct {
    ShowTimestamps bool
    ShowPlayground bool
    DeclLinks      bool
+   Mode           PageInfoMode

    // NotesRx optionally specifies a regexp to match
    // notes to render in the output.
diff --git a/godoc/server.go b/godoc/server.go
index 17514418..bbeef2b3 100644
--- a/godoc/server.go
+++ b/godoc/server.go
@@ -395,6 +395,10 @@ func (m PageInfoMode) names() []string {
 // URL form value "m". It is value is a comma-separated list of mode names
 // as defined by modeNames (e.g.: m=src,text).
 func (p *Presentation) GetPageInfoMode(r *http.Request) PageInfoMode {
+   if p.Mode != 0 {
+       return p.Mode
+   }
+
    var mode PageInfoMode
    for _, k := range strings.Split(r.FormValue(PageInfoModeQueryString), ",") {
        if m, found := modeNames[strings.TrimSpace(k)]; found {

@rsc would there be a chance this is revisited? I just had a team member complain that it makes development of internal packages annoying and unfriendly, making them hesitant whether they should even use an internal directory at all; and I seen it only fair to agree with them that it's a PITA. Please remember that newbies are the only ones that can tell us "the emperor has no clothes", as we're already so used to it that we don't notice the papercuts anymore, and we already grew weird reflexes to overcome them.

?m=all also shows unexported symbols which can make the godoc for a large package quite verbose.

Was this page helpful?
0 / 5 - 0 ratings