diff --git a/godoc/index.go b/godoc/index.go index 640aa81138..d5332d2384 100644 --- a/godoc/index.go +++ b/godoc/index.go @@ -132,7 +132,7 @@ const removeDuplicates = true // A KindRun is a run of SpotInfos of the same kind in a given file. // The kind (3 bits) is stored in each SpotInfo element; to find the -// kind of a KindRun, look at any of it's elements. +// kind of a KindRun, look at any of its elements. type KindRun []SpotInfo // KindRuns are sorted by line number or index. Since the isIndex bit @@ -698,6 +698,7 @@ func (x *Indexer) indexDocs(dirname string, filename string, astFile *ast.File) if pkgName == "main" { return } + dirname = pathpkg.Clean(dirname) astPkg := ast.Package{ Name: pkgName, Files: map[string]*ast.File{ @@ -705,18 +706,35 @@ func (x *Indexer) indexDocs(dirname string, filename string, astFile *ast.File) }, } var m doc.Mode - docPkg := doc.New(&astPkg, pathpkg.Clean(dirname), m) + docPkg := doc.New(&astPkg, dirname, m) addIdent := func(sk SpotKind, name string, docstr string) { if x.idents[sk] == nil { x.idents[sk] = make(map[string][]Ident) } x.idents[sk][name] = append(x.idents[sk][name], Ident{ - Path: pathpkg.Clean(dirname), + Path: dirname, Package: pkgName, Name: name, Doc: doc.Synopsis(docstr), }) } + foundPkg := false + if x.idents[PackageClause] != nil { + pkgs := x.idents[PackageClause][docPkg.Name] + for i, p := range pkgs { + if p.Path == dirname { + foundPkg = true + if docPkg.Doc != "" { + p.Doc = doc.Synopsis(docPkg.Doc) + pkgs[i] = p + } + break + } + } + } + if !foundPkg { + addIdent(PackageClause, docPkg.Name, docPkg.Doc) + } for _, c := range docPkg.Consts { for _, name := range c.Names { addIdent(ConstDecl, name, c.Doc) @@ -769,7 +787,7 @@ func (x *Indexer) indexGoFile(dirname string, filename string, file *token.File, // Test files are already filtered out in visitFile if IndexGoCode and // IndexFullText are false. Otherwise, check here. isTestFile := (x.c.IndexGoCode || x.c.IndexFullText) && - (strings.HasSuffix(filename, "_test.go") || strings.HasPrefix(dirname, "test/")) + (strings.HasSuffix(filename, "_test.go") || strings.HasPrefix(dirname, "/test/")) if !isTestFile { x.indexDocs(dirname, filename, astFile) } @@ -816,7 +834,7 @@ func (x *Indexer) visitFile(dirname string, fi os.FileInfo) { case x.c.IndexDocs: if !goFile || strings.HasSuffix(fi.Name(), "_test.go") || - strings.HasPrefix(dirname, "test/") { + strings.HasPrefix(dirname, "/test/") { return } default: diff --git a/godoc/static/searchcode.html b/godoc/static/searchcode.html index 22cd0c7356..a032e642c6 100644 --- a/godoc/static/searchcode.html +++ b/godoc/static/searchcode.html @@ -4,6 +4,19 @@ license that can be found in the LICENSE file. --> {{$query_url := urlquery .Query}} +{{if not .Idents}} + {{with .Pak}} +
+
| {{$pkg_html}} |
-
| {{$pkg_html}} |
{{comment_html .Doc}}
+{{comment_html .Doc}}
{{else}} -No documentation available
+No documentation available
{{end}} {{end}} {{end}} diff --git a/godoc/static/static.go b/godoc/static/static.go index df75f100a0..ad409d3f1a 100644 --- a/godoc/static/static.go +++ b/godoc/static/static.go @@ -1447,6 +1447,19 @@ function PlaygroundOutput(el) { license that can be found in the LICENSE file. --> {{$query_url := urlquery .Query}} +{{if not .Idents}} + {{with .Pak}} ++
| {{$pkg_html}} |
-
| {{$pkg_html}} |
{{comment_html .Doc}}
+{{comment_html .Doc}}
{{else}} -No documentation available
+No documentation available
{{end}} {{end}} {{end}}