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

     1  This test exercises deep completion.
     2  
     3  -- settings.json --
     4  {
     5  	"completeUnimported": false,
     6  	"matcher": "caseInsensitive"
     7  }
     8  
     9  -- flags --
    10  -ignore_extra_diags
    11  
    12  -- go.mod --
    13  module golang.org/lsptests
    14  
    15  go 1.18
    16  
    17  -- deep/deep.go --
    18  package deep
    19  
    20  import "context"
    21  
    22  type deepA struct {
    23  	b deepB //@item(deepBField, "b", "deepB", "field")
    24  }
    25  
    26  type deepB struct {
    27  }
    28  
    29  func wantsDeepB(deepB) {}
    30  
    31  func _() {
    32  	var a deepA   //@item(deepAVar, "a", "deepA", "var")
    33  	a.b           //@item(deepABField, "a.b", "deepB", "field")
    34  	wantsDeepB(a) //@complete(")", deepABField, deepAVar)
    35  
    36  	deepA{a} //@snippet("}", deepABField, "a.b")
    37  }
    38  
    39  func wantsContext(context.Context) {}
    40  
    41  func _() {
    42  	context.Background() //@item(ctxBackground, "context.Background", "func() context.Context", "func", "Background returns a non-nil, empty Context.")
    43  	context.TODO()       //@item(ctxTODO, "context.TODO", "func() context.Context", "func", "TODO returns a non-nil, empty Context.")
    44  
    45  	wantsContext(c) //@rank(")", ctxBackground),rank(")", ctxTODO)
    46  }
    47  
    48  func _() {
    49  	var cork struct{ err error }
    50  	cork.err         //@item(deepCorkErr, "cork.err", "error", "field")
    51  	context          //@item(deepContextPkg, "context", "\"context\"", "package")
    52  	var _ error = co // rank(" //", deepCorkErr, deepContextPkg)
    53  }
    54  
    55  func _() {
    56  	// deepCircle is circular.
    57  	type deepCircle struct {
    58  		*deepCircle
    59  	}
    60  	var circle deepCircle   //@item(deepCircle, "circle", "deepCircle", "var")
    61  	circle.deepCircle       //@item(deepCircleField, "circle.deepCircle", "*deepCircle", "field")
    62  	var _ deepCircle = circ //@complete(" //", deepCircle, deepCircleField),snippet(" //", deepCircleField, "*circle.deepCircle")
    63  }
    64  
    65  func _() {
    66  	type deepEmbedC struct {
    67  	}
    68  	type deepEmbedB struct {
    69  		deepEmbedC
    70  	}
    71  	type deepEmbedA struct {
    72  		deepEmbedB
    73  	}
    74  
    75  	wantsC := func(deepEmbedC) {}
    76  
    77  	var a deepEmbedA //@item(deepEmbedA, "a", "deepEmbedA", "var")
    78  	a.deepEmbedB     //@item(deepEmbedB, "a.deepEmbedB", "deepEmbedB", "field")
    79  	a.deepEmbedC     //@item(deepEmbedC, "a.deepEmbedC", "deepEmbedC", "field")
    80  	wantsC(a)        //@complete(")", deepEmbedC, deepEmbedA, deepEmbedB)
    81  }
    82  
    83  func _() {
    84  	type nested struct {
    85  		a int
    86  		n *nested //@item(deepNestedField, "n", "*nested", "field")
    87  	}
    88  
    89  	nested{
    90  		a: 123, //@complete(" //", deepNestedField)
    91  	}
    92  }
    93  
    94  func _() {
    95  	var a struct {
    96  		b struct {
    97  			c int
    98  		}
    99  		d int
   100  	}
   101  
   102  	a.d   //@item(deepAD, "a.d", "int", "field")
   103  	a.b.c //@item(deepABC, "a.b.c", "int", "field")
   104  	a.b   //@item(deepAB, "a.b", "struct{...}", "field")
   105  	a     //@item(deepA, "a", "struct{...}", "var")
   106  
   107  	// "a.d" should be ranked above the deeper "a.b.c"
   108  	var i int
   109  	i = a //@complete(" //", deepAD, deepABC, deepA, deepAB)
   110  }