mirror of
https://github.com/golang/go
synced 2024-11-25 07:17:56 -07:00
cmd/godoc: provide a link from notes to source location
R=golang-dev, r CC=golang-dev https://golang.org/cl/8122043
This commit is contained in:
parent
c676b8b27b
commit
f1b7c140ff
@ -169,9 +169,9 @@
|
||||
{{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 $ .}}">☞</a> {{html .Body}}</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
{{end}}
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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,
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user