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

     1  This test checks that we correctly determine pkgsite links for various
     2  identifiers.
     3  
     4  We should only produce links that work, meaning the object is reachable via the
     5  package's public API.
     6  
     7  Requires go1.19+ for the new go/doc/comment package.
     8  
     9  -- flags --
    10  -min_go=go1.19
    11  
    12  -- go.mod --
    13  module mod.com
    14  
    15  go 1.18
    16  -- p.go --
    17  package p
    18  
    19  type E struct {
    20  	Embed int
    21  }
    22  
    23  // T is in the package scope, and so should be linkable.
    24  type T struct{ //@hover("T", "T", T)
    25  	// Only exported fields should be linkable
    26  
    27  	f int //@hover("f", "f", f)
    28  	F int //@hover("F", "F", F)
    29  
    30  	E
    31  
    32  	// TODO(rfindley): is the link here correct? It ignores N.
    33  	N struct {
    34  		// Nested fields should also be linkable.
    35  		Nested int //@hover("Nested", "Nested", Nested)
    36  	}
    37  }
    38  // M is an exported method, and so should be linkable.
    39  func (T) M() {}
    40  
    41  // m is not exported, and so should not be linkable.
    42  func (T) m() {}
    43  
    44  func _() {
    45  	var t T
    46  
    47  	// Embedded fields should be linkable.
    48  	_ = t.Embed //@hover("Embed", "Embed", Embed)
    49  
    50  	// Local variables should not be linkable, even if they are capitalized.
    51  	var X int //@hover("X", "X", X)
    52  	_ = X
    53  
    54  	// Local types should not be linkable, even if they are capitalized.
    55  	type Local struct { //@hover("Local", "Local", Local)
    56  		E
    57  	}
    58  
    59  	// But the embedded field should still be linkable.
    60  	var l Local
    61  	_ = l.Embed //@hover("Embed", "Embed", Embed)
    62  }
    63  -- @Embed --
    64  ```go
    65  field Embed int
    66  ```
    67  
    68  [`(p.E).Embed` on pkg.go.dev](https://pkg.go.dev/mod.com#E.Embed)
    69  -- @F --
    70  ```go
    71  field F int
    72  ```
    73  
    74  @hover("F", "F", F)
    75  
    76  
    77  [`(p.T).F` on pkg.go.dev](https://pkg.go.dev/mod.com#T.F)
    78  -- @Local --
    79  ```go
    80  type Local struct {
    81  	E
    82  }
    83  ```
    84  
    85  Local types should not be linkable, even if they are capitalized.
    86  
    87  
    88  ```go
    89  // Embedded fields:
    90  Embed int // through E 
    91  ```
    92  -- @Nested --
    93  ```go
    94  field Nested int
    95  ```
    96  
    97  Nested fields should also be linkable.
    98  -- @T --
    99  ```go
   100  type T struct {
   101  	f int //@hover("f", "f", f)
   102  	F int //@hover("F", "F", F)
   103  
   104  	E
   105  
   106  	// TODO(rfindley): is the link here correct? It ignores N.
   107  	N struct {
   108  		// Nested fields should also be linkable.
   109  		Nested int //@hover("Nested", "Nested", Nested)
   110  	}
   111  }
   112  ```
   113  
   114  T is in the package scope, and so should be linkable.
   115  
   116  
   117  ```go
   118  // Embedded fields:
   119  Embed int // through E 
   120  ```
   121  
   122  ```go
   123  func (T) M()
   124  func (T) m()
   125  ```
   126  
   127  [`p.T` on pkg.go.dev](https://pkg.go.dev/mod.com#T)
   128  -- @X --
   129  ```go
   130  var X int
   131  ```
   132  
   133  Local variables should not be linkable, even if they are capitalized.
   134  -- @f --
   135  ```go
   136  field f int
   137  ```
   138  
   139  @hover("f", "f", f)