golang.org/x/tools/gopls@v0.15.3/internal/test/marker/testdata/inlayhints/inlayhints.txt (about) 1 2 -- flags -- 3 -ignore_extra_diags 4 5 -- settings.json -- 6 { 7 "hints": { 8 "assignVariableTypes": true, 9 "compositeLiteralFields": true, 10 "compositeLiteralTypes": true, 11 "constantValues": true, 12 "functionTypeParameters": true, 13 "parameterNames": true, 14 "rangeVariabletypes": true 15 } 16 } 17 18 -- composite_literals.go -- 19 package inlayHint //@inlayhints(complit) 20 21 import "fmt" 22 23 func fieldNames() { 24 for _, c := range []struct { 25 in, want string 26 }{ 27 struct{ in, want string }{"Hello, world", "dlrow ,olleH"}, 28 {"Hello, 世界", "界世 ,olleH"}, 29 {"", ""}, 30 } { 31 fmt.Println(c.in == c.want) 32 } 33 } 34 35 func fieldNamesPointers() { 36 for _, c := range []*struct { 37 in, want string 38 }{ 39 &struct{ in, want string }{"Hello, world", "dlrow ,olleH"}, 40 {"Hello, 世界", "界世 ,olleH"}, 41 {"", ""}, 42 } { 43 fmt.Println(c.in == c.want) 44 } 45 } 46 47 -- @complit -- 48 package inlayHint //@inlayhints(complit) 49 50 import "fmt" 51 52 func fieldNames() { 53 for _, c := range []struct { 54 in, want string 55 }{ 56 struct{ in, want string }{<in: >"Hello, world", <want: >"dlrow ,olleH"}, 57 <struct{in string; want string}>{<in: >"Hello, 世界", <want: >"界世 ,olleH"}, 58 <struct{in string; want string}>{<in: >"", <want: >""}, 59 } { 60 fmt.Println(<a...: >c.in == c.want) 61 } 62 } 63 64 func fieldNamesPointers() { 65 for _, c := range []*struct { 66 in, want string 67 }{ 68 &struct{ in, want string }{<in: >"Hello, world", <want: >"dlrow ,olleH"}, 69 <&struct{in string; want string}>{<in: >"Hello, 世界", <want: >"界世 ,olleH"}, 70 <&struct{in string; want string}>{<in: >"", <want: >""}, 71 } { 72 fmt.Println(<a...: >c.in == c.want) 73 } 74 } 75 76 -- constant_values.go -- 77 package inlayHint //@inlayhints(values) 78 79 const True = true 80 81 type Kind int 82 83 const ( 84 KindNone Kind = iota 85 KindPrint 86 KindPrintf 87 KindErrorf 88 ) 89 90 const ( 91 u = iota * 4 92 v float64 = iota * 42 93 w = iota * 42 94 ) 95 96 const ( 97 a, b = 1, 2 98 c, d 99 e, f = 5 * 5, "hello" + "world" 100 g, h 101 i, j = true, f 102 ) 103 104 // No hint 105 const ( 106 Int = 3 107 Float = 3.14 108 Bool = true 109 Rune = '3' 110 Complex = 2.7i 111 String = "Hello, world!" 112 ) 113 114 var ( 115 varInt = 3 116 varFloat = 3.14 117 varBool = true 118 varRune = '3' + '4' 119 varComplex = 2.7i 120 varString = "Hello, world!" 121 ) 122 123 -- @values -- 124 package inlayHint //@inlayhints(values) 125 126 const True = true 127 128 type Kind int 129 130 const ( 131 KindNone Kind = iota< = 0> 132 KindPrint< = 1> 133 KindPrintf< = 2> 134 KindErrorf< = 3> 135 ) 136 137 const ( 138 u = iota * 4< = 0> 139 v float64 = iota * 42< = 42> 140 w = iota * 42< = 84> 141 ) 142 143 const ( 144 a, b = 1, 2 145 c, d< = 1, 2> 146 e, f = 5 * 5, "hello" + "world"< = 25, "helloworld"> 147 g, h< = 25, "helloworld"> 148 i, j = true, f< = true, "helloworld"> 149 ) 150 151 // No hint 152 const ( 153 Int = 3 154 Float = 3.14 155 Bool = true 156 Rune = '3' 157 Complex = 2.7i 158 String = "Hello, world!" 159 ) 160 161 var ( 162 varInt = 3 163 varFloat = 3.14 164 varBool = true 165 varRune = '3' + '4' 166 varComplex = 2.7i 167 varString = "Hello, world!" 168 ) 169 170 -- parameter_names.go -- 171 package inlayHint //@inlayhints(parameters) 172 173 import "fmt" 174 175 func hello(name string) string { 176 return "Hello " + name 177 } 178 179 func helloWorld() string { 180 return hello("World") 181 } 182 183 type foo struct{} 184 185 func (*foo) bar(baz string, qux int) int { 186 if baz != "" { 187 return qux + 1 188 } 189 return qux 190 } 191 192 func kase(foo int, bar bool, baz ...string) { 193 fmt.Println(foo, bar, baz) 194 } 195 196 func kipp(foo string, bar, baz string) { 197 fmt.Println(foo, bar, baz) 198 } 199 200 func plex(foo, bar string, baz string) { 201 fmt.Println(foo, bar, baz) 202 } 203 204 func tars(foo string, bar, baz string) { 205 fmt.Println(foo, bar, baz) 206 } 207 208 func foobar() { 209 var x foo 210 x.bar("", 1) 211 kase(0, true, "c", "d", "e") 212 kipp("a", "b", "c") 213 plex("a", "b", "c") 214 tars("a", "b", "c") 215 foo, bar, baz := "a", "b", "c" 216 kipp(foo, bar, baz) 217 plex("a", bar, baz) 218 tars(foo+foo, (bar), "c") 219 220 } 221 222 -- @parameters -- 223 package inlayHint //@inlayhints(parameters) 224 225 import "fmt" 226 227 func hello(name string) string { 228 return "Hello " + name 229 } 230 231 func helloWorld() string { 232 return hello(<name: >"World") 233 } 234 235 type foo struct{} 236 237 func (*foo) bar(baz string, qux int) int { 238 if baz != "" { 239 return qux + 1 240 } 241 return qux 242 } 243 244 func kase(foo int, bar bool, baz ...string) { 245 fmt.Println(<a...: >foo, bar, baz) 246 } 247 248 func kipp(foo string, bar, baz string) { 249 fmt.Println(<a...: >foo, bar, baz) 250 } 251 252 func plex(foo, bar string, baz string) { 253 fmt.Println(<a...: >foo, bar, baz) 254 } 255 256 func tars(foo string, bar, baz string) { 257 fmt.Println(<a...: >foo, bar, baz) 258 } 259 260 func foobar() { 261 var x foo 262 x.bar(<baz: >"", <qux: >1) 263 kase(<foo: >0, <bar: >true, <baz...: >"c", "d", "e") 264 kipp(<foo: >"a", <bar: >"b", <baz: >"c") 265 plex(<foo: >"a", <bar: >"b", <baz: >"c") 266 tars(<foo: >"a", <bar: >"b", <baz: >"c") 267 foo< string>, bar< string>, baz< string> := "a", "b", "c" 268 kipp(foo, bar, baz) 269 plex(<foo: >"a", bar, baz) 270 tars(<foo: >foo+foo, <bar: >(bar), <baz: >"c") 271 272 } 273 274 -- type_params.go -- 275 package inlayHint //@inlayhints(typeparams) 276 277 func main() { 278 ints := map[string]int64{ 279 "first": 34, 280 "second": 12, 281 } 282 283 floats := map[string]float64{ 284 "first": 35.98, 285 "second": 26.99, 286 } 287 288 SumIntsOrFloats[string, int64](ints) 289 SumIntsOrFloats[string, float64](floats) 290 291 SumIntsOrFloats(ints) 292 SumIntsOrFloats(floats) 293 294 SumNumbers(ints) 295 SumNumbers(floats) 296 } 297 298 type Number interface { 299 int64 | float64 300 } 301 302 func SumIntsOrFloats[K comparable, V int64 | float64](m map[K]V) V { 303 var s V 304 for _, v := range m { 305 s += v 306 } 307 return s 308 } 309 310 func SumNumbers[K comparable, V Number](m map[K]V) V { 311 var s V 312 for _, v := range m { 313 s += v 314 } 315 return s 316 } 317 318 -- @typeparams -- 319 package inlayHint //@inlayhints(typeparams) 320 321 func main() { 322 ints< map[string]int64> := map[string]int64{ 323 "first": 34, 324 "second": 12, 325 } 326 327 floats< map[string]float64> := map[string]float64{ 328 "first": 35.98, 329 "second": 26.99, 330 } 331 332 SumIntsOrFloats[string, int64](<m: >ints) 333 SumIntsOrFloats[string, float64](<m: >floats) 334 335 SumIntsOrFloats<[string, int64]>(<m: >ints) 336 SumIntsOrFloats<[string, float64]>(<m: >floats) 337 338 SumNumbers<[string, int64]>(<m: >ints) 339 SumNumbers<[string, float64]>(<m: >floats) 340 } 341 342 type Number interface { 343 int64 | float64 344 } 345 346 func SumIntsOrFloats[K comparable, V int64 | float64](m map[K]V) V { 347 var s V 348 for _, v := range m { 349 s += v 350 } 351 return s 352 } 353 354 func SumNumbers[K comparable, V Number](m map[K]V) V { 355 var s V 356 for _, v := range m { 357 s += v 358 } 359 return s 360 } 361 362 -- variable_types.go -- 363 package inlayHint //@inlayhints(vartypes) 364 365 func assignTypes() { 366 i, j := 0, len([]string{})-1 367 println(i, j) 368 } 369 370 func rangeTypes() { 371 for k, v := range []string{} { 372 println(k, v) 373 } 374 } 375 376 func funcLitType() { 377 myFunc := func(a string) string { return "" } 378 } 379 380 func compositeLitType() { 381 foo := map[string]interface{}{"": ""} 382 } 383 384 -- @vartypes -- 385 package inlayHint //@inlayhints(vartypes) 386 387 func assignTypes() { 388 i< int>, j< int> := 0, len([]string{})-1 389 println(i, j) 390 } 391 392 func rangeTypes() { 393 for k, v := range []string{} { 394 println(k, v) 395 } 396 } 397 398 func funcLitType() { 399 myFunc< func(a string) string> := func(a string) string { return "" } 400 } 401 402 func compositeLitType() { 403 foo< map[string]interface{}> := map[string]interface{}{"": ""} 404 } 405