go.tools/godoc: restore line anchors to the source view.
These were removed when adding the -analysis flag (CL 60540044), ostensibly for performance, but I can't reproduce the serious slowdowns I saw then. In any case, they are needed for certain URLs. Fixes golang/go#7743 LGTM=bgarcia R=bgarcia CC=golang-codereviews https://golang.org/cl/86150043
This commit is contained in:
parent
87f95283ac
commit
7f24a8300e
|
@ -527,6 +527,9 @@ func (p *Presentation) serveTextFile(w http.ResponseWriter, r *http.Request, abs
|
||||||
// decorating it with the specified analysis links.
|
// decorating it with the specified analysis links.
|
||||||
//
|
//
|
||||||
func formatGoSource(buf *bytes.Buffer, text []byte, links []analysis.Link, pattern string, selection Selection) {
|
func formatGoSource(buf *bytes.Buffer, text []byte, links []analysis.Link, pattern string, selection Selection) {
|
||||||
|
// Emit to a temp buffer so that we can add line anchors at the end.
|
||||||
|
saved, buf := buf, new(bytes.Buffer)
|
||||||
|
|
||||||
var i int
|
var i int
|
||||||
var link analysis.Link // shared state of the two funcs below
|
var link analysis.Link // shared state of the two funcs below
|
||||||
segmentIter := func() (seg Segment) {
|
segmentIter := func() (seg Segment) {
|
||||||
|
@ -548,6 +551,18 @@ func formatGoSource(buf *bytes.Buffer, text []byte, links []analysis.Link, patte
|
||||||
}
|
}
|
||||||
|
|
||||||
FormatSelections(buf, text, linkWriter, segmentIter, selectionTag, comments, highlights, selection)
|
FormatSelections(buf, text, linkWriter, segmentIter, selectionTag, comments, highlights, selection)
|
||||||
|
|
||||||
|
// Now copy buf to saved, adding line anchors.
|
||||||
|
|
||||||
|
// The lineSelection mechanism can't be composed with our
|
||||||
|
// linkWriter, so we have to add line spans as another pass.
|
||||||
|
n := 1
|
||||||
|
for _, line := range bytes.Split(buf.Bytes(), []byte("\n")) {
|
||||||
|
fmt.Fprintf(saved, "<span id=\"L%d\" class=\"ln\">%6d</span>\t", n, n)
|
||||||
|
n++
|
||||||
|
saved.Write(line)
|
||||||
|
saved.WriteByte('\n')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Presentation) serveDirectory(w http.ResponseWriter, r *http.Request, abspath, relpath string) {
|
func (p *Presentation) serveDirectory(w http.ResponseWriter, r *http.Request, abspath, relpath string) {
|
||||||
|
|
Loading…
Reference in New Issue