From: Robert Griesemer Date: Fri, 24 Feb 2012 21:44:22 +0000 (-0800) Subject: go/doc, godoc: fix range of type declarations X-Git-Tag: weekly.2012-03-04~156 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=0a33b703e61c89cc883304eb627826c875aa4bf2;p=gostls13.git 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 --- diff --git a/src/pkg/go/doc/reader.go b/src/pkg/go/doc/reader.go index 3558892ebd..5eaae37b7d 100644 --- a/src/pkg/go/doc/reader.go +++ b/src/pkg/go/doc/reader.go @@ -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}, }