Commit 0a33b703 authored by Robert Griesemer's avatar Robert Griesemer

go/doc, godoc: fix range of type declarations

For grouped type declarations, go/doc introduces
fake individual declarations. Don't use the original
location of the "type" keyword because it will lead
to an overly large source code range for that fake
declaration, and thus an overly large selection shown
via godoc (e.g.: click on the AssignStmt link for:
http://golang.org/pkg/go/ast/#AssignStmt ).

Also: Don't create a fake declaration if not needed.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5694061
parent b36d25f1
......@@ -432,6 +432,17 @@ func (r *reader) readFile(src *ast.File) {
r.readValue(d)
case token.TYPE:
// types are handled individually
if len(d.Specs) == 1 && !d.Lparen.IsValid() {
// common case: single declaration w/o parentheses
// (if a single declaration is parenthesized,
// create a new fake declaration below, so that
// go/doc type declarations always appear w/o
// parentheses)
if s, ok := d.Specs[0].(*ast.TypeSpec); ok {
r.readType(d, s)
}
break
}
for _, spec := range d.Specs {
if s, ok := spec.(*ast.TypeSpec); ok {
// use an individual (possibly fake) declaration
......@@ -439,8 +450,13 @@ func (r *reader) readFile(src *ast.File) {
// gets to (re-)use the declaration documentation
// if there's none associated with the spec itself
fake := &ast.GenDecl{
Doc: d.Doc,
TokPos: d.Pos(),
Doc: d.Doc,
// don't use the existing TokPos because it
// will lead to the wrong selection range for
// the fake declaration if there are more
// than one type in the group (this affects
// src/cmd/godoc/godoc.go's posLink_urlFunc)
TokPos: s.Pos(),
Tok: token.TYPE,
Specs: []ast.Spec{s},
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment