Skip to content

Commit

Permalink
godoc: fix missing (Added in Go) "x.xx" for function with type parame…
Browse files Browse the repository at this point in the history
…ters

For HTML documentation using godoc, since the introduction of type
parameters, the new API for function with type parameters has not been
rendered recently (no 1.XX displayed on the right).

This changes fix it by checking for "[" first in the function name
before "(".

Change-Id: I9421e095bbce7ffe5f871441160d6cc87cc3f299
Reviewed-on: https://go-review.googlesource.com/c/tools/+/639475
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
  • Loading branch information
shuLhan authored and gopherbot committed Jan 3, 2025
1 parent 98a190b commit 39e1a8c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion godoc/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func parseRow(s string) (vr versionedRow, ok bool) {
case strings.HasPrefix(rest, "func "):
vr.kind = "func"
rest = rest[len("func "):]
if i := strings.IndexByte(rest, '('); i != -1 {
if i := strings.IndexAny(rest, "[("); i != -1 {
vr.name = rest[:i]
return vr, true
}
Expand Down
21 changes: 21 additions & 0 deletions godoc/versions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,27 @@ func TestParseVersionRow(t *testing.T) {
recv: "Encoding",
},
},
{
// Function with type parameters.
// Taken from "go/src/api/go1.21.txt".
row: "pkg cmp, func Compare[$0 Ordered]($0, $0) int #59488",
want: versionedRow{
pkg: "cmp",
kind: "func",
name: "Compare",
},
},
{
// Function without type parameter but have "[" after
// "(" should have works as is.
// Taken from "go/src/api/go1.21.txt".
row: "pkg bytes, func ContainsFunc([]uint8, func(int32) bool) bool #54386",
want: versionedRow{
pkg: "bytes",
kind: "func",
name: "ContainsFunc",
},
},
}

for i, tt := range tests {
Expand Down

0 comments on commit 39e1a8c

Please sign in to comment.