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

     1  This test checks definition and hover operations over embedded fields and methods.
     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.18
    12  
    13  -- a/a.go --
    14  package a
    15  
    16  type A string //@loc(AString, "A")
    17  
    18  func (_ A) Hi() {} //@loc(AHi, "Hi")
    19  
    20  type S struct {
    21  	Field int //@loc(SField, "Field")
    22  	R         // embed a struct
    23  	H         // embed an interface
    24  }
    25  
    26  type R struct {
    27  	Field2 int //@loc(RField2, "Field2")
    28  }
    29  
    30  func (r R) Hey() {} //@loc(RHey, "Hey")
    31  
    32  type H interface { //@loc(H, "H")
    33  	Goodbye() //@loc(HGoodbye, "Goodbye")
    34  }
    35  
    36  type I interface { //@loc(I, "I")
    37  	B() //@loc(IB, "B")
    38  	J
    39  }
    40  
    41  type J interface { //@loc(J, "J")
    42  	Hello() //@loc(JHello, "Hello")
    43  }
    44  
    45  -- b/b.go --
    46  package b
    47  
    48  import "mod.com/a" //@loc(AImport, re"\".*\"")
    49  
    50  type embed struct {
    51  	F int //@loc(F, "F")
    52  }
    53  
    54  func (embed) M() //@loc(M, "M")
    55  
    56  type Embed struct {
    57  	embed
    58  	*a.A
    59  	a.I
    60  	a.S
    61  }
    62  
    63  func _() {
    64  	e := Embed{}
    65  	e.Hi()      //@def("Hi", AHi),hover("Hi", "Hi", AHi)
    66  	e.B()       //@def("B", IB),hover("B", "B", IB)
    67  	_ = e.Field     //@def("Field", SField),hover("Field", "Field", SField)
    68  	_ = e.Field2    //@def("Field2", RField2),hover("Field2", "Field2", RField2)
    69  	e.Hello()   //@def("Hello", JHello),hover("Hello", "Hello",JHello)
    70  	e.Hey()     //@def("Hey", RHey),hover("Hey", "Hey", RHey)
    71  	e.Goodbye() //@def("Goodbye", HGoodbye),hover("Goodbye", "Goodbye", HGoodbye)
    72  	e.M() //@def("M", M),hover("M", "M", M)
    73  	_ = e.F //@def("F", F),hover("F", "F", F)
    74  }
    75  
    76  type aAlias = a.A //@loc(aAlias, "aAlias")
    77  
    78  type S1 struct { //@loc(S1, "S1")
    79  	F1     int //@loc(S1F1, "F1")
    80  	S2         //@loc(S1S2, "S2"),def("S2", S2),hover("S2", "S2", S2)
    81  	a.A        //@def("A", AString),hover("A", "A", aA)
    82  	aAlias     //@def("a", aAlias),hover("a", "aAlias", aAlias)
    83  }
    84  
    85  type S2 struct { //@loc(S2, "S2")
    86  	F1   string //@loc(S2F1, "F1")
    87  	F2   int    //@loc(S2F2, "F2")
    88  	*a.A        //@def("A", AString),def("a",AImport)
    89  }
    90  
    91  type S3 struct {
    92  	F1 struct {
    93  		a.A //@def("A", AString)
    94  	}
    95  }
    96  
    97  func Bar() {
    98  	var x S1    //@def("S1", S1),hover("S1", "S1", S1)
    99  	_ = x.S2    //@def("S2", S1S2),hover("S2", "S2", S1S2)
   100  	_ = x.F1    //@def("F1", S1F1),hover("F1", "F1", S1F1)
   101  	_ = x.F2    //@def("F2", S2F2),hover("F2", "F2", S2F2)
   102  	_ = x.S2.F1 //@def("F1", S2F1),hover("F1", "F1", S2F1)
   103  }
   104  
   105  -- b/c.go --
   106  package b
   107  
   108  var _ = S1{ //@def("S1", S1),hover("S1", "S1", S1)
   109  	F1: 99, //@def("F1", S1F1),hover("F1", "F1", S1F1)
   110  }
   111  
   112  -- @AHi --
   113  ```go
   114  func (a.A) Hi()
   115  ```
   116  
   117  [`(a.A).Hi` on pkg.go.dev](https://pkg.go.dev/mod.com/a#A.Hi)
   118  -- @F --
   119  ```go
   120  field F int
   121  ```
   122  
   123  @loc(F, "F")
   124  
   125  
   126  [`(b.Embed).F` on pkg.go.dev](https://pkg.go.dev/mod.com/b#Embed.F)
   127  -- @HGoodbye --
   128  ```go
   129  func (a.H) Goodbye()
   130  ```
   131  
   132  @loc(HGoodbye, "Goodbye")
   133  
   134  
   135  [`(a.H).Goodbye` on pkg.go.dev](https://pkg.go.dev/mod.com/a#H.Goodbye)
   136  -- @IB --
   137  ```go
   138  func (a.I) B()
   139  ```
   140  
   141  @loc(IB, "B")
   142  
   143  
   144  [`(a.I).B` on pkg.go.dev](https://pkg.go.dev/mod.com/a#I.B)
   145  -- @JHello --
   146  ```go
   147  func (a.J) Hello()
   148  ```
   149  
   150  @loc(JHello, "Hello")
   151  
   152  
   153  [`(a.J).Hello` on pkg.go.dev](https://pkg.go.dev/mod.com/a#J.Hello)
   154  -- @M --
   155  ```go
   156  func (embed) M()
   157  ```
   158  
   159  [`(b.Embed).M` on pkg.go.dev](https://pkg.go.dev/mod.com/b#Embed.M)
   160  -- @RField2 --
   161  ```go
   162  field Field2 int
   163  ```
   164  
   165  @loc(RField2, "Field2")
   166  
   167  
   168  [`(a.R).Field2` on pkg.go.dev](https://pkg.go.dev/mod.com/a#R.Field2)
   169  -- @RHey --
   170  ```go
   171  func (r a.R) Hey()
   172  ```
   173  
   174  [`(a.R).Hey` on pkg.go.dev](https://pkg.go.dev/mod.com/a#R.Hey)
   175  -- @S1 --
   176  ```go
   177  type S1 struct {
   178  	F1     int //@loc(S1F1, "F1")
   179  	S2         //@loc(S1S2, "S2"),def("S2", S2),hover("S2", "S2", S2)
   180  	a.A        //@def("A", AString),hover("A", "A", aA)
   181  	aAlias     //@def("a", aAlias),hover("a", "aAlias", aAlias)
   182  }
   183  ```
   184  
   185  ```go
   186  // Embedded fields:
   187  F2 int // through S2 
   188  ```
   189  
   190  [`b.S1` on pkg.go.dev](https://pkg.go.dev/mod.com/b#S1)
   191  -- @S1F1 --
   192  ```go
   193  field F1 int
   194  ```
   195  
   196  @loc(S1F1, "F1")
   197  
   198  
   199  [`(b.S1).F1` on pkg.go.dev](https://pkg.go.dev/mod.com/b#S1.F1)
   200  -- @S1S2 --
   201  ```go
   202  field S2 S2
   203  ```
   204  
   205  @loc(S1S2, "S2"),def("S2", S2),hover("S2", "S2", S2)
   206  
   207  
   208  [`(b.S1).S2` on pkg.go.dev](https://pkg.go.dev/mod.com/b#S1.S2)
   209  -- @S2 --
   210  ```go
   211  type S2 struct {
   212  	F1   string //@loc(S2F1, "F1")
   213  	F2   int    //@loc(S2F2, "F2")
   214  	*a.A        //@def("A", AString),def("a",AImport)
   215  }
   216  ```
   217  
   218  ```go
   219  func (a.A) Hi()
   220  ```
   221  
   222  [`b.S2` on pkg.go.dev](https://pkg.go.dev/mod.com/b#S2)
   223  -- @S2F1 --
   224  ```go
   225  field F1 string
   226  ```
   227  
   228  @loc(S2F1, "F1")
   229  
   230  
   231  [`(b.S2).F1` on pkg.go.dev](https://pkg.go.dev/mod.com/b#S2.F1)
   232  -- @S2F2 --
   233  ```go
   234  field F2 int
   235  ```
   236  
   237  @loc(S2F2, "F2")
   238  
   239  
   240  [`(b.S2).F2` on pkg.go.dev](https://pkg.go.dev/mod.com/b#S2.F2)
   241  -- @SField --
   242  ```go
   243  field Field int
   244  ```
   245  
   246  @loc(SField, "Field")
   247  
   248  
   249  [`(a.S).Field` on pkg.go.dev](https://pkg.go.dev/mod.com/a#S.Field)
   250  -- @aA --
   251  ```go
   252  type A string
   253  ```
   254  
   255  @loc(AString, "A")
   256  
   257  
   258  ```go
   259  func (a.A) Hi()
   260  ```
   261  
   262  [`a.A` on pkg.go.dev](https://pkg.go.dev/mod.com/a#A)
   263  -- @aAlias --
   264  ```go
   265  type aAlias = a.A
   266  ```
   267  
   268  @loc(aAlias, "aAlias")
   269  
   270  
   271  ```go
   272  func (a.A) Hi()
   273  ```