Skip to content

Commit

Permalink
fix(godocfx): shorten function names (#2880)
Browse files Browse the repository at this point in the history
After this change, function headers show up as `func Foo` rather than
`func Foo(s string) string`, matching the behavior of pkg.go.dev.
  • Loading branch information
tbpg authored Sep 17, 2020
1 parent 8728cdf commit 48a0217
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions internal/godocfx/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,50 +241,44 @@ func parse(glob string) (map[string]*page, tableOfContents, *packages.Module, er
for _, fn := range t.Funcs {
fnUID := uid + "." + fn.Name
pkgItem.addChild(child(fnUID))
s := pkgsite.Synopsis(pkg.Fset, fn.Decl)
pkgPage.addItem(&item{
UID: fnUID,
Name: s,
Name: fmt.Sprintf("func %s\n", fn.Name),
ID: fn.Name,
Parent: uid,
Type: "function",
Summary: fn.Doc,
Langs: onlyGo,
// Note: Name has the syntax already.
// Syntax: Syntax{Content: s},
Syntax: syntax{Content: pkgsite.Synopsis(pkg.Fset, fn.Decl)},
})
}
for _, fn := range t.Methods {
fnUID := uid + "." + fn.Name
pkgItem.addChild(child(fnUID))
s := pkgsite.Synopsis(pkg.Fset, fn.Decl)
pkgPage.addItem(&item{
UID: fnUID,
Name: s,
Name: fmt.Sprintf("func (%s) %s\n", fn.Recv, fn.Name),
ID: fn.Name,
Parent: uid,
Type: "function",
Type: "function", // Note: this is actually a method.
Summary: fn.Doc,
Langs: onlyGo,
// Note: Name has the syntax already.
// Syntax: Syntax{Content: s},
Syntax: syntax{Content: pkgsite.Synopsis(pkg.Fset, fn.Decl)},
})
}
}
for _, fn := range docPkg.Funcs {
uid := pkg.PkgPath + "." + fn.Name
pkgItem.addChild(child(uid))
s := pkgsite.Synopsis(pkg.Fset, fn.Decl)
pkgPage.addItem(&item{
UID: uid,
Name: s,
Name: fmt.Sprintf("func %s\n", fn.Name),
ID: fn.Name,
Parent: pkg.PkgPath,
Type: "function",
Summary: fn.Doc,
Langs: onlyGo,
// Note: Name has the syntax already.
// Syntax: Syntax{Content: s},
Syntax: syntax{Content: pkgsite.Synopsis(pkg.Fset, fn.Decl)},
})
}
}
Expand Down

0 comments on commit 48a0217

Please sign in to comment.