mirror of
https://github.com/golang/go
synced 2024-11-22 08:44:41 -07:00
godoc: show packages matching a query at the top
Also: fix layout of textual search results and fix a field reference in the respective template. Fixes #1987. R=rsc, r CC=golang-dev https://golang.org/cl/4962061
This commit is contained in:
parent
4670d9e634
commit
041dc0a1c2
@ -17,6 +17,17 @@
|
|||||||
{{end}}
|
{{end}}
|
||||||
</p>
|
</p>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
{{with .Pak}}
|
||||||
|
<h2 id="Packages">Package {{html $.Query}}</h2>
|
||||||
|
<p>
|
||||||
|
<table class="layout">
|
||||||
|
{{range .}}
|
||||||
|
{{$pkg_html := pkgLink .Pak.Path | html}}
|
||||||
|
<tr><td><a href="/{{$pkg_html}}">{{$pkg_html}}</a></td></tr>
|
||||||
|
{{end}}
|
||||||
|
</table>
|
||||||
|
</p>
|
||||||
|
{{end}}
|
||||||
{{with .Hit}}
|
{{with .Hit}}
|
||||||
{{with .Decls}}
|
{{with .Decls}}
|
||||||
<h2 id="Global">Package-level declarations</h2>
|
<h2 id="Global">Package-level declarations</h2>
|
||||||
|
@ -1,33 +1,39 @@
|
|||||||
QUERY
|
QUERY
|
||||||
{{.Query}}
|
{{.Query}}
|
||||||
{{with .Alert}}
|
|
||||||
{{.}}
|
{{with .Alert}}{{.}}
|
||||||
{{end}}{{/* .Alert */}}{{/*
|
{{end}}{{/* .Alert */}}{{/*
|
||||||
|
|
||||||
---------------------------------------
|
---------------------------------------
|
||||||
|
|
||||||
*/}}{{with .Alt}}
|
*/}}{{with .Alt}}DID YOU MEAN
|
||||||
DID YOU MEAN
|
|
||||||
{{range .Alts}} {{.}}
|
{{range .Alts}} {{.}}
|
||||||
{{end}}{{end}}{{/* .Alts */}}{{/*
|
{{end}}{{end}}{{/* .Alt */}}{{/*
|
||||||
|
|
||||||
---------------------------------------
|
---------------------------------------
|
||||||
|
|
||||||
*/}}{{with .Hit}}{{with .Decls}}
|
*/}}{{with .Pak}}PACKAGE {{$.Query}}
|
||||||
PACKAGE-LEVEL DECLARATIONS
|
|
||||||
|
{{range .}}{{.Pak.Path}}
|
||||||
|
{{end}}
|
||||||
|
{{end}}{{/* .Pak */}}{{/*
|
||||||
|
|
||||||
|
---------------------------------------
|
||||||
|
|
||||||
|
*/}}{{with .Hit}}{{with .Decls}}PACKAGE-LEVEL DECLARATIONS
|
||||||
|
|
||||||
{{range .}}package {{.Pak.Name}}
|
{{range .}}package {{.Pak.Name}}
|
||||||
{{range $file := .Files}}{{range .Groups}}{{range .Infos}} {{srcLink $file.File.Path}}:{{infoLine .}}{{end}}
|
{{range $file := .Files}}{{range .Groups}}{{range .}} {{srcLink $file.File.Path}}:{{infoLine .}}{{end}}
|
||||||
{{end}}{{end}}{{/* .Files */}}
|
{{end}}{{end}}{{/* .Files */}}
|
||||||
{{end}}{{end}}{{/* .Decls */}}{{/*
|
{{end}}{{end}}{{/* .Decls */}}{{/*
|
||||||
|
|
||||||
---------------------------------------
|
---------------------------------------
|
||||||
|
|
||||||
*/}}{{with .Others}}
|
*/}}{{with .Others}}LOCAL DECLARATIONS AND USES
|
||||||
LOCAL DECLARATIONS AND USES
|
|
||||||
|
|
||||||
{{range .}}package {{.Pak.Name}}
|
{{range .}}package {{.Pak.Name}}
|
||||||
{{range $file := .Files}}{{range .Groups}}{{range .Infos}} {{srcLink $file.File.Path}}:{{infoLine .}}
|
{{range $file := .Files}}{{range .Groups}}{{range .}} {{srcLink $file.File.Path}}:{{infoLine .}}
|
||||||
{{end}}{{end}}{{end}}{{/* .Files */}}
|
{{end}}{{end}}{{end}}{{/* .Files */}}
|
||||||
{{end}}{{end}}{{/* .Others */}}{{end}}{{/* .Hit */}}{{/*
|
{{end}}{{end}}{{/* .Others */}}{{end}}{{/* .Hit */}}{{/*
|
||||||
|
|
||||||
|
@ -1016,6 +1016,7 @@ type SearchResult struct {
|
|||||||
Alert string // error or warning message
|
Alert string // error or warning message
|
||||||
|
|
||||||
// identifier matches
|
// identifier matches
|
||||||
|
Pak HitList // packages matching Query
|
||||||
Hit *LookupResult // identifier matches of Query
|
Hit *LookupResult // identifier matches of Query
|
||||||
Alt *AltWords // alternative identifiers to look for
|
Alt *AltWords // alternative identifiers to look for
|
||||||
|
|
||||||
@ -1034,7 +1035,7 @@ func lookup(query string) (result SearchResult) {
|
|||||||
|
|
||||||
// identifier search
|
// identifier search
|
||||||
var err os.Error
|
var err os.Error
|
||||||
result.Hit, result.Alt, err = index.Lookup(query)
|
result.Pak, result.Hit, result.Alt, err = index.Lookup(query)
|
||||||
if err != nil && *maxResults <= 0 {
|
if err != nil && *maxResults <= 0 {
|
||||||
// ignore the error if full text search is enabled
|
// ignore the error if full text search is enabled
|
||||||
// since the query may be a valid regular expression
|
// since the query may be a valid regular expression
|
||||||
|
@ -344,6 +344,8 @@ func reduce(h0 RunList) HitList {
|
|||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// filter returns a new HitList created by filtering
|
||||||
|
// all PakRuns from h that have a matching pakname.
|
||||||
func (h HitList) filter(pakname string) HitList {
|
func (h HitList) filter(pakname string) HitList {
|
||||||
var hh HitList
|
var hh HitList
|
||||||
for _, p := range h {
|
for _, p := range h {
|
||||||
@ -867,7 +869,7 @@ func (x *Index) Stats() Statistics {
|
|||||||
return x.stats
|
return x.stats
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *Index) LookupWord(w string) (match *LookupResult, alt *AltWords) {
|
func (x *Index) lookupWord(w string) (match *LookupResult, alt *AltWords) {
|
||||||
match = x.words[w]
|
match = x.words[w]
|
||||||
alt = x.alts[canonical(w)]
|
alt = x.alts[canonical(w)]
|
||||||
// remove current spelling from alternatives
|
// remove current spelling from alternatives
|
||||||
@ -891,9 +893,10 @@ func isIdentifier(s string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// For a given query, which is either a single identifier or a qualified
|
// For a given query, which is either a single identifier or a qualified
|
||||||
// identifier, Lookup returns a LookupResult, and a list of alternative
|
// identifier, Lookup returns a list of packages, a LookupResult, and a
|
||||||
// spellings, if any. If the query syntax is wrong, an error is reported.
|
// list of alternative spellings, if any. Any and all results may be nil.
|
||||||
func (x *Index) Lookup(query string) (match *LookupResult, alt *AltWords, err os.Error) {
|
// If the query syntax is wrong, an error is reported.
|
||||||
|
func (x *Index) Lookup(query string) (paks HitList, match *LookupResult, alt *AltWords, err os.Error) {
|
||||||
ss := strings.Split(query, ".")
|
ss := strings.Split(query, ".")
|
||||||
|
|
||||||
// check query syntax
|
// check query syntax
|
||||||
@ -904,15 +907,23 @@ func (x *Index) Lookup(query string) (match *LookupResult, alt *AltWords, err os
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handle simple and qualified identifiers
|
||||||
switch len(ss) {
|
switch len(ss) {
|
||||||
case 1:
|
case 1:
|
||||||
match, alt = x.LookupWord(ss[0])
|
ident := ss[0]
|
||||||
|
match, alt = x.lookupWord(ident)
|
||||||
|
if match != nil {
|
||||||
|
// found a match - filter packages with same name
|
||||||
|
// for the list of packages called ident, if any
|
||||||
|
paks = match.Others.filter(ident)
|
||||||
|
}
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
pakname := ss[0]
|
pakname, ident := ss[0], ss[1]
|
||||||
match, alt = x.LookupWord(ss[1])
|
match, alt = x.lookupWord(ident)
|
||||||
if match != nil {
|
if match != nil {
|
||||||
// found a match - filter by package name
|
// found a match - filter by package name
|
||||||
|
// (no paks - package names are not qualified)
|
||||||
decls := match.Decls.filter(pakname)
|
decls := match.Decls.filter(pakname)
|
||||||
others := match.Others.filter(pakname)
|
others := match.Others.filter(pakname)
|
||||||
match = &LookupResult{decls, others}
|
match = &LookupResult{decls, others}
|
||||||
|
Loading…
Reference in New Issue
Block a user