golang.org/x/tools/gopls@v0.15.3/internal/test/marker/testdata/completion/address.txt (about) 1 This test exercises the reference and dereference completion modifiers. 2 3 TODO: remove the need to set "literalCompletions" here, as this is one of the 4 few places this setting is needed. 5 6 -- flags -- 7 -ignore_extra_diags 8 9 -- go.mod -- 10 module golang.org/lsptests 11 12 go 1.18 13 14 -- address/address.go -- 15 package address 16 17 func wantsPtr(*int) {} 18 func wantsVariadicPtr(...*int) {} 19 20 func wantsVariadic(...int) {} 21 22 type foo struct{ c int } //@item(addrFieldC, "c", "int", "field") 23 24 func _() { 25 var ( 26 a string //@item(addrA, "a", "string", "var") 27 b int //@item(addrB, "b", "int", "var") 28 ) 29 30 wantsPtr() //@rank(")", addrB, addrA),snippet(")", addrB, "&b") 31 wantsPtr(&b) //@snippet(")", addrB, "b") 32 33 wantsVariadicPtr() //@rank(")", addrB, addrA),snippet(")", addrB, "&b") 34 35 var s foo 36 s.c //@item(addrDeepC, "s.c", "int", "field") 37 wantsPtr() //@snippet(")", addrDeepC, "&s.c") 38 wantsPtr(s) //@snippet(")", addrDeepC, "&s.c") 39 wantsPtr(&s) //@snippet(")", addrDeepC, "s.c") 40 41 // don't add "&" in item (it gets added as an additional edit) 42 wantsPtr(&s.c) //@snippet(")", addrFieldC, "c") 43 44 // check dereferencing as well 45 var c *int //@item(addrCPtr, "c", "*int", "var") 46 var _ int = _ //@rank("_ //", addrCPtr, addrA),snippet("_ //", addrCPtr, "*c") 47 48 wantsVariadic() //@rank(")", addrCPtr, addrA),snippet(")", addrCPtr, "*c") 49 50 var d **int //@item(addrDPtr, "d", "**int", "var") 51 var _ int = _ //@rank("_ //", addrDPtr, addrA),snippet("_ //", addrDPtr, "**d") 52 53 type namedPtr *int 54 var np namedPtr //@item(addrNamedPtr, "np", "namedPtr", "var") 55 56 var _ int = _ //@rank("_ //", addrNamedPtr, addrA) 57 58 // don't get tripped up by recursive pointer type 59 type dontMessUp *dontMessUp //@item(dontMessUp, "dontMessUp", "*dontMessUp", "type") 60 var dmu *dontMessUp //@item(addrDMU, "dmu", "*dontMessUp", "var") 61 62 var _ int = dmu //@complete(" //", addrDMU, dontMessUp) 63 } 64 65 func (f foo) ptr() *foo { return &f } 66 67 func _() { 68 getFoo := func() foo { return foo{} } 69 70 // not addressable 71 getFoo().c //@item(addrGetFooC, "getFoo().c", "int", "field") 72 73 // addressable 74 getFoo().ptr().c //@item(addrGetFooPtrC, "getFoo().ptr().c", "int", "field") 75 76 wantsPtr() //@snippet(")", addrGetFooPtrC, "&getFoo().ptr().c") 77 wantsPtr(&g) //@snippet(")", addrGetFooPtrC, "getFoo().ptr().c") 78 } 79 80 type nested struct { 81 f foo 82 } 83 84 func _() { 85 getNested := func() nested { return nested{} } 86 87 getNested().f.c //@item(addrNestedC, "getNested().f.c", "int", "field") 88 getNested().f.ptr().c //@item(addrNestedPtrC, "getNested().f.ptr().c", "int", "field") 89 90 // addrNestedC is not addressable, so rank lower 91 wantsPtr(getNestedfc) //@complete(")", addrNestedPtrC, addrNestedC) 92 }