golang.org/x/tools/gopls@v0.15.3/internal/test/marker/testdata/hover/generics.txt (about)

     1  This file contains tests for hovering over generic Go code.
     2  
     3  Requires go1.20+ for the new go/doc/comment package, and a change in Go 1.20
     4  that affected the formatting of constraint interfaces.
     5  
     6  -- flags --
     7  -min_go=go1.20
     8  
     9  -- go.mod --
    10  // A go.mod is require for correct pkgsite links.
    11  // TODO(rfindley): don't link to ad-hoc or command-line-arguments packages!
    12  module mod.com
    13  
    14  go 1.18
    15  
    16  -- generics.go --
    17  package generics
    18  
    19  type value[T any] struct { //hover("lue", "value", value),hover("T", "T", valueT)
    20  	val T   //@hover("T", "T", valuevalT)
    21  	Q   int //@hover("Q", "Q", valueQ)
    22  }
    23  
    24  type Value[T any] struct { //@hover("T", "T", ValueT)
    25  	val T   //@hover("T", "T", ValuevalT)
    26  	Q   int //@hover("Q", "Q", ValueQ)
    27  }
    28  
    29  func F[P interface{ ~int | string }]() { //@hover("P", "P", Ptparam)
    30  	var _ P //@hover("P","P",Pvar)
    31  }
    32  
    33  -- inferred.go --
    34  package generics
    35  
    36  func app[S interface{ ~[]E }, E interface{}](s S, e E) S {
    37  	return append(s, e)
    38  }
    39  
    40  func _() {
    41  	_ = app[[]int]             //@hover("app", "app", appint)
    42  	_ = app[[]int, int]        //@hover("app", "app", appint)
    43  	_ = app[[]int]([]int{}, 0) //@hover("app", "app", appint), diag("[[]int]", re"unnecessary")
    44  	_ = app([]int{}, 0)        //@hover("app", "app", appint)
    45  }
    46  
    47  -- @ValueQ --
    48  ```go
    49  field Q int
    50  ```
    51  
    52  @hover("Q", "Q", ValueQ)
    53  
    54  
    55  [`(generics.Value).Q` on pkg.go.dev](https://pkg.go.dev/mod.com#Value.Q)
    56  -- @ValueT --
    57  ```go
    58  type parameter T any
    59  ```
    60  -- @ValuevalT --
    61  ```go
    62  type parameter T any
    63  ```
    64  -- @appint --
    65  ```go
    66  func app(s []int, e int) []int // func[S interface{~[]E}, E interface{}](s S, e E) S
    67  ```
    68  -- @valueQ --
    69  ```go
    70  field Q int
    71  ```
    72  
    73  @hover("Q", "Q", valueQ)
    74  -- @valuevalT --
    75  ```go
    76  type parameter T any
    77  ```
    78  -- @Ptparam --
    79  ```go
    80  type parameter P interface{~int | string}
    81  ```
    82  -- @Pvar --
    83  ```go
    84  type parameter P interface{~int | string}
    85  ```