Skip to content

Commit 39e1a8c

Browse files
shuLhangopherbot
authored andcommitted
godoc: fix missing (Added in Go) "x.xx" for function with type parameters
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 <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 98a190b commit 39e1a8c

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

godoc/versions.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func parseRow(s string) (vr versionedRow, ok bool) {
189189
case strings.HasPrefix(rest, "func "):
190190
vr.kind = "func"
191191
rest = rest[len("func "):]
192-
if i := strings.IndexByte(rest, '('); i != -1 {
192+
if i := strings.IndexAny(rest, "[("); i != -1 {
193193
vr.name = rest[:i]
194194
return vr, true
195195
}

godoc/versions_test.go

+21
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,27 @@ func TestParseVersionRow(t *testing.T) {
6565
recv: "Encoding",
6666
},
6767
},
68+
{
69+
// Function with type parameters.
70+
// Taken from "go/src/api/go1.21.txt".
71+
row: "pkg cmp, func Compare[$0 Ordered]($0, $0) int #59488",
72+
want: versionedRow{
73+
pkg: "cmp",
74+
kind: "func",
75+
name: "Compare",
76+
},
77+
},
78+
{
79+
// Function without type parameter but have "[" after
80+
// "(" should have works as is.
81+
// Taken from "go/src/api/go1.21.txt".
82+
row: "pkg bytes, func ContainsFunc([]uint8, func(int32) bool) bool #54386",
83+
want: versionedRow{
84+
pkg: "bytes",
85+
kind: "func",
86+
name: "ContainsFunc",
87+
},
88+
},
6889
}
6990

7091
for i, tt := range tests {

0 commit comments

Comments
 (0)