godoc: remove the function declaration link

The link of the function declaration part is unnecessary because it points to the same place.
Removed the link of the function declaration part.

"IdentMode" has been removed since it is no longer used.

Fixes golang/go#20269

Change-Id: I6399899947e46dc84c5432c1d645f6d96b7db4f6
Reviewed-on: https://go-review.googlesource.com/42892
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Masahiro Furudate 2017-05-07 04:40:42 +09:00 committed by Brad Fitzpatrick
parent 15c7897560
commit ce1291533b
2 changed files with 37 additions and 22 deletions

View File

@ -202,6 +202,28 @@ var <span id="S">S</span> <a href="#T">T</a> = <a href="#T">T</a>{<a href="#T.X"
}
}
func TestFuncDeclNotLink(t *testing.T) {
// Function.
got := linkifySource(t, []byte(`
package http
func Get(url string) (resp *Response, err error)`))
want := `func Get(url <a href="/pkg/builtin/#string">string</a>) (resp *<a href="#Response">Response</a>, err <a href="/pkg/builtin/#error">error</a>)`
if got != want {
t.Errorf("got: %s\n\nwant: %s\n", got, want)
}
// Method.
got = linkifySource(t, []byte(`
package http
func (h Header) Get(key string) string`))
want = `func (h <a href="#Header">Header</a>) Get(key <a href="/pkg/builtin/#string">string</a>) <a href="/pkg/builtin/#string">string</a>`
if got != want {
t.Errorf("got: %s\n\nwant: %s\n", got, want)
}
}
func linkifySource(t *testing.T, src []byte) string {
p := &Presentation{
DeclLinks: true,

View File

@ -53,7 +53,7 @@ func LinkifyText(w io.Writer, text []byte, n ast.Node) {
prev = "a"
case info.path == "" && info.name != "":
// local identifier
if info.mode == identVal {
if info.isVal {
fmt.Fprintf(w, `<span id="%s">`, info.name)
prev = "span"
} else if ast.IsExported(info.name) {
@ -74,19 +74,10 @@ func LinkifyText(w io.Writer, text []byte, n ast.Node) {
// The zero value of a link represents "no link".
//
type link struct {
mode identMode
path, name string // package path, identifier name
isVal bool // identifier is defined in a const or var declaration
}
// The identMode describes how an identifier is "used" at its source location.
type identMode int
const (
identUse identMode = iota // identifier is used (must be zero value for identMode)
identDef // identifier is defined
identVal // identifier is defined in a const or var declaration
)
// linksFor returns the list of links for the identifiers used
// by node in the same order as they appear in the source.
//
@ -101,18 +92,20 @@ func linksFor(node ast.Node) (links []link) {
switch n := node.(type) {
case *ast.Field:
for _, n := range n.Names {
linkMap[n] = link{mode: identDef}
linkMap[n] = link{}
}
case *ast.ImportSpec:
if name := n.Name; name != nil {
linkMap[name] = link{mode: identDef}
linkMap[name] = link{}
}
case *ast.ValueSpec:
for _, n := range n.Names {
linkMap[n] = link{mode: identVal, name: n.Name}
linkMap[n] = link{name: n.Name, isVal: true}
}
case *ast.FuncDecl:
linkMap[n.Name] = link{}
case *ast.TypeSpec:
linkMap[n.Name] = link{mode: identDef}
linkMap[n.Name] = link{}
case *ast.AssignStmt:
// Short variable declarations only show up if we apply
// this code to all source code (as opposed to exported
@ -125,7 +118,7 @@ func linksFor(node ast.Node) (links []link) {
// Each lhs expression should be an
// ident, but we are conservative and check.
if n, _ := x.(*ast.Ident); n != nil {
linkMap[n] = link{mode: identVal}
linkMap[n] = link{isVal: true}
}
}
}
@ -141,8 +134,8 @@ func linksFor(node ast.Node) (links []link) {
if path, err := strconv.Unquote(spec.Path.Value); err == nil {
// Register two links, one for the package
// and one for the qualified identifier.
linkMap[x] = link{mode: identUse, path: path}
linkMap[n.Sel] = link{mode: identUse, path: path, name: n.Sel.Name}
linkMap[x] = link{path: path}
linkMap[n.Sel] = link{path: path, name: n.Sel.Name}
}
}
}
@ -164,8 +157,8 @@ func linksFor(node ast.Node) (links []link) {
if path, err := strconv.Unquote(spec.Path.Value); err == nil {
// Register two links, one for the package
// and one for the qualified identifier.
linkMap[x] = link{mode: identUse, path: path}
linkMap[typ.Sel] = link{mode: identUse, path: path, name: typ.Sel.Name}
linkMap[x] = link{path: path}
linkMap[typ.Sel] = link{path: path, name: typ.Sel.Name}
fieldPath = path
prefix = typ.Sel.Name + "."
}
@ -180,7 +173,7 @@ func linksFor(node ast.Node) (links []link) {
// if this is a struct literal or a map literal without type
// information. We assume struct literal.
name := prefix + k.Name
linkMap[k] = link{mode: identUse, path: fieldPath, name: name}
linkMap[k] = link{path: fieldPath, name: name}
}
}
}
@ -188,7 +181,7 @@ func linksFor(node ast.Node) (links []link) {
if l, ok := linkMap[n]; ok {
links = append(links, l)
} else {
l := link{mode: identUse, name: n.Name}
l := link{name: n.Name}
if n.Obj == nil && predeclared[n.Name] {
l.path = builtinPkgPath
}