]> Cypherpunks repositories - gostls13.git/commitdiff
godoc search bug fixes:
authorRobert Griesemer <gri@golang.org>
Tue, 27 Oct 2009 23:08:12 +0000 (16:08 -0700)
committerRobert Griesemer <gri@golang.org>
Tue, 27 Oct 2009 23:08:12 +0000 (16:08 -0700)
- 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

doc/style.css
lib/godoc/godoc.html
lib/godoc/search.html
src/cmd/godoc/godoc.go
src/cmd/godoc/index.go

index 84c29c077b34f888113c6c5bf582173bd48bbbf4..d2dd7c9022f8ca744f9ce348094c7dffcd4a4690 100644 (file)
@@ -167,6 +167,11 @@ span.highlight {
 /* ------------------------------------------------------------------------- */
 /* Styles used by infoClassFmt */
 
+a.package {
+  text-decoration: none;
+  background-color: #FFFFFF;
+}
+
 a.import {
   text-decoration: none;
   background-color: #D8D8D8;
index b77a1301bb7e8f7c4efe854099a7a8480012fb14..df8ee882a06ec92a4e8880972140c8652e029c39 100644 (file)
 
 <div id="linkList">
   <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="navhead">Documents</li>
-    <li><a href="/doc/go_spec.html">Language Specification</a></li>
-    <li><a href="/doc/go_mem.html">Memory Model</a></li>
-    <li><a href="/doc/go_tutorial.html">Tutorial</a></li>
-    <li><a href="/doc/effective_go.html">Effective Go</a></li>
-    <li><a href="/doc/go_faq.html">FAQ</a></li>
-    <li><a href="/doc/go_lang_faq.html">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_spec.html" class="noline">Language Specification</a></li>
+    <li><a href="/doc/go_mem.html" class="noline">Memory Model</a></li>
+    <li><a href="/doc/go_tutorial.html" class="noline">Tutorial</a></li>
+    <li><a href="/doc/effective_go.html" class="noline">Effective Go</a></li>
+    <li><a href="/doc/go_faq.html" class="noline">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" class="noline">Go for C++ Programmers</a></li>
 
     <li class="blank">&nbsp;</li>
     <li class="navhead">How To</li>
-    <li><a href="/doc/install.html">Install Go</a></li>
-    <li><a href="/doc/contribute.html">Contribute code</a></li>
+    <li><a href="/doc/install.html" class="noline">Install Go</a></li>
+    <li><a href="/doc/contribute.html" class="noline">Contribute code</a></li>
 
     <li class="blank">&nbsp;</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="navhead">Go code search</li>
index 419a9f8d0df645d2a7b239ca0034c18d1ebbdd7b..e054dd5b0b04dd9672789d78f1a0a7230bbe615e 100644 (file)
@@ -25,7 +25,7 @@
                        <h3>package {Pak.Name|html}</h3>
                        {.repeated section Files}
                                {.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>
                                {.end}
                        {.end}
index 168c816f92a48ded1ac5712a21200ea45adf89a3..845c9e510bd750b47b6972c520c9bd87e1e999ec 100644 (file)
@@ -349,6 +349,7 @@ func linkFmt(w io.Writer, x interface{}, format string) {
 
 
 var infoClasses = [nKinds]string{
+       "package",      // PackageClause
        "import",       // ImportDecl
        "const",        // ConstDecl
        "type", // TypeDecl
index 1cd6c5ca5db702c6f98f7dc373ed98e2018c5613..9db87a7d44f1b5daa6f4e6cb01d149eb0a6cc5e2 100644 (file)
@@ -101,7 +101,8 @@ type SpotInfo uint32
 type SpotKind uint32
 
 const (
-       ImportDecl      SpotKind        = iota;
+       PackageClause   SpotKind        = iota;
+       ImportDecl;
        ConstDecl;
        TypeDecl;
        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.
 func makeSpotInfo(kind SpotKind, lori int, isIndex bool) SpotInfo {
        // 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 {
-       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.
 func newFileRun(h *RunList, i, j int) interface{} {
        file := h.At(i).(Spot).File;
-       lines := make([]SpotInfo, j-i);
-       prev := 0;
+       infos := make([]SpotInfo, j-i);
        k := 0;
        for ; i < j; i++ {
-               info := h.At(i).(Spot).Info;
-               // ignore line duplicates
-               // (if lori is a snippet index it is unique - no need to check IsIndex())
-               lori := info.Lori();
-               if lori != prev {
-                       lines[k] = info;
-                       prev = lori;
+               infos[k] = h.At(i).(Spot).Info;
+               k++;
+       }
+       run := &FileRun{file, infos};
+       // Spots were sorted by file to create this run.
+       // Within this run, sort them by line number.
+       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++;
+                       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);
                }
 
+       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:
                return true;
        }