]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/godoc: provide a link from notes to source location
authorRobert Griesemer <gri@golang.org>
Thu, 28 Mar 2013 21:40:59 +0000 (14:40 -0700)
committerRobert Griesemer <gri@golang.org>
Thu, 28 Mar 2013 21:40:59 +0000 (14:40 -0700)
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/8122043

lib/godoc/package.html
src/cmd/godoc/godoc.go
src/pkg/go/doc/doc.go
src/pkg/go/doc/reader.go

index 5dcc9f9a2093bfaa20f28bbe34c1c36b03cc6e15..a7d47298a5dbbeea712e87f5209eddcc219626f7 100644 (file)
        {{with $.Notes}}
                {{range $marker, $content := .}}
                        <h2 id="pkg-note-{{$marker}}">{{noteTitle $marker | html}}s</h2>
-                       <ul>
+                       <ul style="list-style: none; padding: 0;">
                        {{range .}}
-                       <li>{{html .Body}}</li>
+                       <li><a href="{{posLink_url $ .}}">&#x261e;</a> {{html .Body}}</li>
                        {{end}}
                        </ul>
                {{end}}
index 2e05c50598c4be03750d52293c2fa02078e2df11..6f585fee8820de3aab9daff3eeb472170f9e862d 100644 (file)
@@ -481,19 +481,33 @@ func pkgLinkFunc(path string) string {
        return pkgHandler.pattern[1:] + relpath // remove trailing '/' for relative URL
 }
 
-func posLink_urlFunc(info *PageInfo, node ast.Node) string {
+// n must be an ast.Node or a *doc.Note
+func posLink_urlFunc(info *PageInfo, n interface{}) string {
+       var pos, end token.Pos
+
+       switch n := n.(type) {
+       case ast.Node:
+               pos = n.Pos()
+               end = n.End()
+       case *doc.Note:
+               pos = n.Pos
+               end = n.End
+       default:
+               panic(fmt.Sprintf("wrong type for posLink_url template formatter: %T", n))
+       }
+
        var relpath string
        var line int
-       var low, high int // selection
+       var low, high int // selection offset range
 
-       if p := node.Pos(); p.IsValid() {
-               pos := info.FSet.Position(p)
-               relpath = pos.Filename
-               line = pos.Line
-               low = pos.Offset
+       if pos.IsValid() {
+               p := info.FSet.Position(pos)
+               relpath = p.Filename
+               line = p.Line
+               low = p.Offset
        }
-       if p := node.End(); p.IsValid() {
-               high = info.FSet.Position(p).Offset
+       if end.IsValid() {
+               high = info.FSet.Position(end).Offset
        }
 
        var buf bytes.Buffer
index 1f114179326a2599eb8bf72b74c969fe6544ebf9..4264940a0cd5ca20ff5a0d27d18f548f4ad6aa2d 100644 (file)
@@ -69,9 +69,9 @@ type Func struct {
 // at least one character is recognized. The ":" following the uid is optional.
 // Notes are collected in the Package.Notes map indexed by the notes marker.
 type Note struct {
-       Pos  token.Pos // position of the comment containing the marker
-       UID  string    // uid found with the marker
-       Body string    // note body text
+       Pos, End token.Pos // position range of the comment containing the marker
+       UID      string    // uid found with the marker
+       Body     string    // note body text
 }
 
 // Mode values control the operation of New.
index 7e1422d0c4d1346e4f92a4c5a9bb2dc2fb0362b3..4fa6fd9d599f0e7f3644c015e8879df3abba5bc0 100644 (file)
@@ -419,6 +419,7 @@ func (r *reader) readNote(list []*ast.Comment) {
                        marker := text[m[2]:m[3]]
                        r.notes[marker] = append(r.notes[marker], &Note{
                                Pos:  list[0].Pos(),
+                               End:  list[len(list)-1].End(),
                                UID:  text[m[4]:m[5]],
                                Body: body,
                        })