godoc: fix addNames for generics

The type of a function receiver can now also be a IndexExpr.

Fixes golang/go#50413

Change-Id: I5ac7bee8ea6b594be00d00c7fed2e2a9fe260b10
Reviewed-on: https://go-review.googlesource.com/c/tools/+/373857
Trust: Than McIntosh <thanm@google.com>
Run-TryBot: Alessandro Arzilli <alessandro.arzilli@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
diff --git a/godoc/server.go b/godoc/server.go
index 48e8d95..9c5d556 100644
--- a/godoc/server.go
+++ b/godoc/server.go
@@ -30,6 +30,7 @@
 	"golang.org/x/tools/godoc/analysis"
 	"golang.org/x/tools/godoc/util"
 	"golang.org/x/tools/godoc/vfs"
+	"golang.org/x/tools/internal/typeparams"
 )
 
 // handlerServer is a migration from an old godoc http Handler type.
@@ -462,12 +463,19 @@
 	case *ast.FuncDecl:
 		name := d.Name.Name
 		if d.Recv != nil {
+			r := d.Recv.List[0].Type
+			if rr, isstar := r.(*ast.StarExpr); isstar {
+				r = rr.X
+			}
+
 			var typeName string
-			switch r := d.Recv.List[0].Type.(type) {
-			case *ast.StarExpr:
-				typeName = r.X.(*ast.Ident).Name
+			switch x := r.(type) {
 			case *ast.Ident:
-				typeName = r.Name
+				typeName = x.Name
+			case *ast.IndexExpr:
+				typeName = x.X.(*ast.Ident).Name
+			case *typeparams.IndexListExpr:
+				typeName = x.X.(*ast.Ident).Name
 			}
 			name = typeName + "_" + name
 		}