1
0
mirror of https://github.com/golang/go synced 2024-11-25 00:07:56 -07:00

godoc search bug fixes:

- sort by package name (instead of package path) for results with snippets
- sort line numbers in results without snippets
- properly characterize package clauses
- experiment with a leaner look: no underlines for top-level godoc links in the left side bar

Still using colors to distinguish results. Next step.

R=rsc
http://go/go-review/1015016
This commit is contained in:
Robert Griesemer 2009-10-27 16:08:12 -07:00
parent 32810a5ded
commit e3fd2e1ec6
5 changed files with 74 additions and 24 deletions

View File

@ -167,6 +167,11 @@ span.highlight {
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
/* Styles used by infoClassFmt */ /* Styles used by infoClassFmt */
a.package {
text-decoration: none;
background-color: #FFFFFF;
}
a.import { a.import {
text-decoration: none; text-decoration: none;
background-color: #D8D8D8; background-color: #D8D8D8;

View File

@ -25,26 +25,26 @@
<div id="linkList"> <div id="linkList">
<ul> <ul>
<li class="navhead"><a href="/">Home</a></li> <li class="navhead"><a href="/" class="noline">Home</a></li>
<li class="blank">&nbsp;</li> <li class="blank">&nbsp;</li>
<li class="navhead">Documents</li> <li class="navhead">Documents</li>
<li><a href="/doc/go_spec.html">Language Specification</a></li> <li><a href="/doc/go_spec.html" class="noline">Language Specification</a></li>
<li><a href="/doc/go_mem.html">Memory Model</a></li> <li><a href="/doc/go_mem.html" class="noline">Memory Model</a></li>
<li><a href="/doc/go_tutorial.html">Tutorial</a></li> <li><a href="/doc/go_tutorial.html" class="noline">Tutorial</a></li>
<li><a href="/doc/effective_go.html">Effective Go</a></li> <li><a href="/doc/effective_go.html" class="noline">Effective Go</a></li>
<li><a href="/doc/go_faq.html">FAQ</a></li> <li><a href="/doc/go_faq.html" class="noline">FAQ</a></li>
<li><a href="/doc/go_lang_faq.html">Language Design FAQ</a></li> <li><a href="/doc/go_lang_faq.html" class="noline">Language Design FAQ</a></li>
<li><a href="/doc/go_for_cpp_programmers.html">Go for C++ Programmers</a></li> <li><a href="/doc/go_for_cpp_programmers.html" class="noline">Go for C++ Programmers</a></li>
<li class="blank">&nbsp;</li> <li class="blank">&nbsp;</li>
<li class="navhead">How To</li> <li class="navhead">How To</li>
<li><a href="/doc/install.html">Install Go</a></li> <li><a href="/doc/install.html" class="noline">Install Go</a></li>
<li><a href="/doc/contribute.html">Contribute code</a></li> <li><a href="/doc/contribute.html" class="noline">Contribute code</a></li>
<li class="blank">&nbsp;</li> <li class="blank">&nbsp;</li>
<li class="navhead">Programming</li> <li class="navhead">Programming</li>
<li><a href="/pkg">Package documentation</a></li> <li><a href="/pkg" class="noline">Package documentation</a></li>
<li class="blank">&nbsp;</li> <li class="blank">&nbsp;</li>
<li class="navhead">Go code search</li> <li class="navhead">Go code search</li>

View File

@ -25,7 +25,7 @@
<h3>package {Pak.Name|html}</h3> <h3>package {Pak.Name|html}</h3>
{.repeated section Files} {.repeated section Files}
{.repeated section Infos} {.repeated section Infos}
<a href="{File.Path|html}?h={Query|html}#L{@|infoLine}">{File.Path|html}:{@|infoLine}</a> <a href="{File.Path|html}?h={Query|html}#L{@|infoLine}" class="noline">{File.Path|html}:{@|infoLine}</a>
<pre>{@|infoSnippet}</pre> <pre>{@|infoSnippet}</pre>
{.end} {.end}
{.end} {.end}

View File

@ -349,6 +349,7 @@ func linkFmt(w io.Writer, x interface{}, format string) {
var infoClasses = [nKinds]string{ var infoClasses = [nKinds]string{
"package", // PackageClause
"import", // ImportDecl "import", // ImportDecl
"const", // ConstDecl "const", // ConstDecl
"type", // TypeDecl "type", // TypeDecl

View File

@ -101,7 +101,8 @@ type SpotInfo uint32
type SpotKind uint32 type SpotKind uint32
const ( const (
ImportDecl SpotKind = iota; PackageClause SpotKind = iota;
ImportDecl;
ConstDecl; ConstDecl;
TypeDecl; TypeDecl;
VarDecl; VarDecl;
@ -112,6 +113,15 @@ const (
) )
func init() {
// sanity check: if nKinds is too large, the SpotInfo
// accessor functions may need to be updated
if nKinds > 8 {
panic();
}
}
// makeSpotInfo makes a SpotInfo. // makeSpotInfo makes a SpotInfo.
func makeSpotInfo(kind SpotKind, lori int, isIndex bool) SpotInfo { func makeSpotInfo(kind SpotKind, lori int, isIndex bool) SpotInfo {
// encode lori: bits [4..32) // encode lori: bits [4..32)
@ -159,8 +169,9 @@ type Pak struct {
} }
// Paks are sorted by name (primary key) and by import path (secondary key).
func (p *Pak) less(q *Pak) bool { func (p *Pak) less(q *Pak) bool {
return p.Path < q.Path || p.Name < q.Name; return p.Name < q.Name || p.Name == q.Name && p.Path < q.Path;
} }
@ -196,24 +207,46 @@ type FileRun struct {
} }
func (f *FileRun) Len() int {
return len(f.Infos);
}
func (f *FileRun) Less(i, j int) bool {
return f.Infos[i].less(f.Infos[j]);
}
func (f *FileRun) Swap(i, j int) {
f.Infos[i], f.Infos[j] = f.Infos[j], f.Infos[i];
}
// newFileRun allocates a new *FileRun from the Spot run [i, j) in h. // newFileRun allocates a new *FileRun from the Spot run [i, j) in h.
func newFileRun(h *RunList, i, j int) interface{} { func newFileRun(h *RunList, i, j int) interface{} {
file := h.At(i).(Spot).File; file := h.At(i).(Spot).File;
lines := make([]SpotInfo, j-i); infos := make([]SpotInfo, j-i);
prev := 0;
k := 0; k := 0;
for ; i < j; i++ { for ; i < j; i++ {
info := h.At(i).(Spot).Info; infos[k] = h.At(i).(Spot).Info;
// ignore line duplicates k++;
// (if lori is a snippet index it is unique - no need to check IsIndex()) }
lori := info.Lori(); run := &FileRun{file, infos};
if lori != prev { // Spots were sorted by file to create this run.
lines[k] = info; // Within this run, sort them by line number.
prev = lori; sort.Sort(run);
// Remove duplicates: Both the lori and kind field
// must be the same for duplicate, and since the
// isIndex field is always the same for all infos
// in one list we can simply compare the entire
// info.
k = 0;
var prev SpotInfo;
for i, x := range infos {
if x != prev || i == 0 {
infos[k] = x;
k++; k++;
prev = x;
} }
} }
return &FileRun{file, lines[0:k]}; run.Infos = infos[0:k];
return run;
} }
@ -500,6 +533,17 @@ func (x *Indexer) Visit(node interface{}) bool {
ast.Walk(x, n.Type); ast.Walk(x, n.Type);
} }
case *ast.File:
x.visitComment(n.Doc);
x.decl = nil;
x.visitIdent(PackageClause, n.Name);
for _, d := range n.Decls {
ast.Walk(x, d);
}
// don't visit package level comments for now
// to avoid duplicate visiting from individual
// nodes
default: default:
return true; return true;
} }