aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2010-09-15 15:07:52 -0700
committerRobert Griesemer <gri@golang.org>2010-09-15 15:07:52 -0700
commit108f5c913c74304f89ffcc6b12536c465d9fb42d (patch)
treef93273739f147a421efb13af6d55c13859e0eebc
parentabb73a4a867431913e137718288a496cfb959ef3 (diff)
downloadgo-108f5c913c74304f89ffcc6b12536c465d9fb42d.tar.gz
go-108f5c913c74304f89ffcc6b12536c465d9fb42d.zip
godoc: only show directories containing true package files
(ignore directories containing *.go files that don't actually start with a package clause) R=r CC=golang-dev https://golang.org/cl/2223041
-rw-r--r--src/cmd/godoc/dirtrees.go45
1 files changed, 25 insertions, 20 deletions
diff --git a/src/cmd/godoc/dirtrees.go b/src/cmd/godoc/dirtrees.go
index 028bae99d3..dfc5ab2ce0 100644
--- a/src/cmd/godoc/dirtrees.go
+++ b/src/cmd/godoc/dirtrees.go
@@ -101,35 +101,40 @@ func (b *treeBuilder) newDirTree(path, name string, depth int) *Directory {
list, _ := ioutil.ReadDir(path) // ignore errors
- // determine number of subdirectories and package files
+ // determine number of subdirectories and if there are package files
ndirs := 0
- nfiles := 0
+ hasPkgFiles := false
var synopses [4]string // prioritized package documentation (0 == highest priority)
for _, d := range list {
switch {
case isPkgDir(d):
ndirs++
case isPkgFile(d):
- nfiles++
+ // looks like a package file, but may just be a file ending in ".go";
+ // don't just count it yet (otherwise we may end up with hasPkgFiles even
+ // though the directory doesn't contain any real package files - was bug)
if synopses[0] == "" {
// no "optimal" package synopsis yet; continue to collect synopses
file, err := parser.ParseFile(pathutil.Join(path, d.Name), nil,
parser.ParseComments|parser.PackageClauseOnly)
- if err == nil && file.Doc != nil {
- // prioritize documentation
- i := -1
- switch file.Name.Name {
- case name:
- i = 0 // normal case: directory name matches package name
- case fakePkgName:
- i = 1 // synopses for commands
- case "main":
- i = 2 // directory contains a main package
- default:
- i = 3 // none of the above
- }
- if 0 <= i && i < len(synopses) && synopses[i] == "" {
- synopses[i] = firstSentence(doc.CommentText(file.Doc))
+ if err == nil {
+ hasPkgFiles = true
+ if file.Doc != nil {
+ // prioritize documentation
+ i := -1
+ switch file.Name.Name {
+ case name:
+ i = 0 // normal case: directory name matches package name
+ case fakePkgName:
+ i = 1 // synopses for commands
+ case "main":
+ i = 2 // directory contains a main package
+ default:
+ i = 3 // none of the above
+ }
+ if 0 <= i && i < len(synopses) && synopses[i] == "" {
+ synopses[i] = firstSentence(doc.CommentText(file.Doc))
+ }
}
}
}
@@ -154,8 +159,8 @@ func (b *treeBuilder) newDirTree(path, name string, depth int) *Directory {
}
// if there are no package files and no subdirectories
- // (with package files), ignore the directory
- if nfiles == 0 && len(dirs) == 0 {
+ // containing package files, ignore the directory
+ if !hasPkgFiles && len(dirs) == 0 {
return nil
}