mirror of
https://github.com/golang/go
synced 2024-11-25 17:57: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}}
|
{{with $.Notes}}
|
||||||
{{range $marker, $content := .}}
|
{{range $marker, $content := .}}
|
||||||
<h2 id="pkg-note-{{$marker}}">{{noteTitle $marker | html}}s</h2>
|
<h2 id="pkg-note-{{$marker}}">{{noteTitle $marker | html}}s</h2>
|
||||||
<ul>
|
<ul style="list-style: none; padding: 0;">
|
||||||
{{range .}}
|
{{range .}}
|
||||||
<li>{{html .Body}}</li>
|
<li><a href="{{posLink_url $ .}}">☞</a> {{html .Body}}</li>
|
||||||
{{end}}
|
{{end}}
|
||||||
</ul>
|
</ul>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
@ -481,19 +481,33 @@ func pkgLinkFunc(path string) string {
|
|||||||
return pkgHandler.pattern[1:] + relpath // remove trailing '/' for relative URL
|
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 relpath string
|
||||||
var line int
|
var line int
|
||||||
var low, high int // selection
|
var low, high int // selection offset range
|
||||||
|
|
||||||
if p := node.Pos(); p.IsValid() {
|
if pos.IsValid() {
|
||||||
pos := info.FSet.Position(p)
|
p := info.FSet.Position(pos)
|
||||||
relpath = pos.Filename
|
relpath = p.Filename
|
||||||
line = pos.Line
|
line = p.Line
|
||||||
low = pos.Offset
|
low = p.Offset
|
||||||
}
|
}
|
||||||
if p := node.End(); p.IsValid() {
|
if end.IsValid() {
|
||||||
high = info.FSet.Position(p).Offset
|
high = info.FSet.Position(end).Offset
|
||||||
}
|
}
|
||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
|
@ -69,7 +69,7 @@ type Func struct {
|
|||||||
// at least one character is recognized. The ":" following the uid is optional.
|
// 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.
|
// Notes are collected in the Package.Notes map indexed by the notes marker.
|
||||||
type Note struct {
|
type Note struct {
|
||||||
Pos token.Pos // position of the comment containing the marker
|
Pos, End token.Pos // position range of the comment containing the marker
|
||||||
UID string // uid found with the marker
|
UID string // uid found with the marker
|
||||||
Body string // note body text
|
Body string // note body text
|
||||||
}
|
}
|
||||||
|
@ -419,6 +419,7 @@ func (r *reader) readNote(list []*ast.Comment) {
|
|||||||
marker := text[m[2]:m[3]]
|
marker := text[m[2]:m[3]]
|
||||||
r.notes[marker] = append(r.notes[marker], &Note{
|
r.notes[marker] = append(r.notes[marker], &Note{
|
||||||
Pos: list[0].Pos(),
|
Pos: list[0].Pos(),
|
||||||
|
End: list[len(list)-1].End(),
|
||||||
UID: text[m[4]:m[5]],
|
UID: text[m[4]:m[5]],
|
||||||
Body: body,
|
Body: body,
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user