golang.org/x/tools/gopls@v0.15.3/internal/test/marker/testdata/hover/linkable_generics.txt (about) 1 This file contains tests for documentation links to generic code in hover. 2 3 Requires go1.19+ for the new go/doc/comment package. 4 5 -- flags -- 6 -min_go=go1.19 7 8 -- go.mod -- 9 module mod.com 10 11 go 1.19 12 13 -- a.go -- 14 package a 15 16 import "mod.com/generic" 17 18 func _() { 19 // Hovering over instantiated object should produce accurate type 20 // information, but link to the generic declarations. 21 22 var x generic.GT[int] //@hover("GT", "GT", xGT) 23 _ = x.F //@hover("x", "x", x),hover("F", "F", xF) 24 25 f := generic.GF[int] //@hover("GF", "GF", fGF) 26 _ = f //@hover("f", "f", f) 27 } 28 29 -- generic/generic.go -- 30 package generic 31 32 // Hovering over type parameters should link to documentation. 33 // 34 // TODO(rfindley): should it? We should probably link to the type. 35 type GT[P any] struct{ //@hover("GT", "GT", GT),hover("P", "P", GTP) 36 F P //@hover("F", "F", F),hover("P", "P", FP) 37 } 38 39 func (GT[P]) M(p P) { //@hover("GT", "GT", GTrecv),hover("M","M", M),hover(re"p (P)", re"p (P)", pP) 40 } 41 42 func GF[P any] (p P) { //@hover("GF", "GF", GF) 43 } 44 45 -- @F -- 46 ```go 47 field F P 48 ``` 49 50 @hover("F", "F", F),hover("P", "P", FP) 51 52 53 [`(generic.GT).F` on pkg.go.dev](https://pkg.go.dev/mod.com/generic#GT.F) 54 -- @FP -- 55 ```go 56 type parameter P any 57 ``` 58 -- @GF -- 59 ```go 60 func GF[P any](p P) 61 ``` 62 63 [`generic.GF` on pkg.go.dev](https://pkg.go.dev/mod.com/generic#GF) 64 -- @GT -- 65 ```go 66 type GT[P any] struct { 67 F P //@hover("F", "F", F),hover("P", "P", FP) 68 } 69 ``` 70 71 Hovering over type parameters should link to documentation. 72 73 TODO(rfindley): should it? We should probably link to the type. 74 75 76 ```go 77 func (GT[P]) M(p P) 78 ``` 79 80 [`generic.GT` on pkg.go.dev](https://pkg.go.dev/mod.com/generic#GT) 81 -- @GTP -- 82 ```go 83 type parameter P any 84 ``` 85 -- @GTrecv -- 86 ```go 87 type GT[P any] struct { 88 F P //@hover("F", "F", F),hover("P", "P", FP) 89 } 90 ``` 91 92 Hovering over type parameters should link to documentation. 93 94 TODO(rfindley): should it? We should probably link to the type. 95 96 97 ```go 98 func (GT[P]) M(p P) 99 ``` 100 101 [`generic.GT` on pkg.go.dev](https://pkg.go.dev/mod.com/generic#GT) 102 -- @M -- 103 ```go 104 func (GT[P]) M(p P) 105 ``` 106 107 [`(generic.GT).M` on pkg.go.dev](https://pkg.go.dev/mod.com/generic#GT.M) 108 -- @f -- 109 ```go 110 var f func(p int) 111 ``` 112 -- @fGF -- 113 ```go 114 func generic.GF(p int) // func[P any](p P) 115 ``` 116 117 [`generic.GF` on pkg.go.dev](https://pkg.go.dev/mod.com/generic#GF) 118 -- @pP -- 119 ```go 120 type parameter P any 121 ``` 122 -- @x -- 123 ```go 124 var x generic.GT[int] 125 ``` 126 127 @hover("GT", "GT", xGT) 128 -- @xF -- 129 ```go 130 field F int 131 ``` 132 133 @hover("F", "F", F),hover("P", "P", FP) 134 135 136 [`(generic.GT).F` on pkg.go.dev](https://pkg.go.dev/mod.com/generic#GT.F) 137 -- @xGT -- 138 ```go 139 type GT[P any] struct { 140 F P //@hover("F", "F", F),hover("P", "P", FP) 141 } 142 ``` 143 144 Hovering over type parameters should link to documentation. 145 146 TODO(rfindley): should it? We should probably link to the type. 147 148 149 ```go 150 func (generic.GT[P]) M(p P) 151 ``` 152 153 [`generic.GT` on pkg.go.dev](https://pkg.go.dev/mod.com/generic#GT)