8 "golang.org/x/tools/internal/lsp/foo"
12 []int{} //@item(litIntSlice, "[]int{}", "", "var")
13 &[]int{} //@item(litIntSliceAddr, "&[]int{}", "", "var")
14 make([]int, 0) //@item(makeIntSlice, "make([]int, 0)", "", "func")
16 var _ *[]int = in //@snippet(" //", litIntSliceAddr, "&[]int{$0\\}", "&[]int{$0\\}")
17 var _ **[]int = in //@complete(" //")
20 slice = i //@snippet(" //", litIntSlice, "[]int{$0\\}", "[]int{$0\\}")
21 slice = m //@snippet(" //", makeIntSlice, "make([]int, ${1:})", "make([]int, ${1:0})")
27 namedInt{} //@item(litNamedSlice, "namedInt{}", "", "var")
28 make(namedInt, 0) //@item(makeNamedSlice, "make(namedInt, 0)", "", "func")
30 var namedSlice namedInt
31 namedSlice = n //@snippet(" //", litNamedSlice, "namedInt{$0\\}", "namedInt{$0\\}")
32 namedSlice = m //@snippet(" //", makeNamedSlice, "make(namedInt, ${1:})", "make(namedInt, ${1:0})")
36 make(chan int) //@item(makeChan, "make(chan int)", "", "func")
39 ch = m //@snippet(" //", makeChan, "make(chan int)", "make(chan int)")
43 map[string]struct{}{} //@item(litMap, "map[string]struct{}{}", "", "var")
44 make(map[string]struct{}) //@item(makeMap, "make(map[string]struct{})", "", "func")
46 var m map[string]struct{}
47 m = m //@snippet(" //", litMap, "map[string]struct{\\}{$0\\}", "map[string]struct{\\}{$0\\}")
48 m = m //@snippet(" //", makeMap, "make(map[string]struct{\\})", "make(map[string]struct{\\})")
50 struct{}{} //@item(litEmptyStruct, "struct{}{}", "", "var")
52 m["hi"] = s //@snippet(" //", litEmptyStruct, "struct{\\}{\\}", "struct{\\}{\\}")
56 type myStruct struct{ i int }
58 myStruct{} //@item(litStruct, "myStruct{}", "", "var")
59 &myStruct{} //@item(litStructPtr, "&myStruct{}", "", "var")
62 ms = m //@snippet(" //", litStruct, "myStruct{$0\\}", "myStruct{$0\\}")
65 msPtr = m //@snippet(" //", litStructPtr, "&myStruct{$0\\}", "&myStruct{$0\\}")
67 msPtr = &m //@snippet(" //", litStruct, "myStruct{$0\\}", "myStruct{$0\\}")
72 func (myImpl) foo() {}
74 func (*myImpl) bar() {}
76 type myBasicImpl string
78 func (myBasicImpl) foo() {}
81 type myIntf interface {
85 myImpl{} //@item(litImpl, "myImpl{}", "", "var")
88 mi = m //@snippet(" //", litImpl, "myImpl{\\}", "myImpl{\\}")
90 myBasicImpl() //@item(litBasicImpl, "myBasicImpl()", "string", "var")
92 mi = m //@snippet(" //", litBasicImpl, "myBasicImpl($0)", "myBasicImpl($0)")
94 // only satisfied by pointer to myImpl
95 type myPtrIntf interface {
99 &myImpl{} //@item(litImplPtr, "&myImpl{}", "", "var")
102 mpi = m //@snippet(" //", litImplPtr, "&myImpl{\\}", "&myImpl{\\}")
106 var s struct{ i []int } //@item(litSliceField, "i", "[]int", "field")
108 // no literal completions after selector
109 foo = s.i //@complete(" //", litSliceField)
113 type myStruct struct{ i int } //@item(litMyStructType, "myStruct", "struct{...}", "struct")
114 myStruct{} //@item(litMyStruct, "myStruct{}", "", "var")
116 foo := func(s string, args ...myStruct) {}
117 // Don't give literal slice candidate for variadic arg.
118 // Do give literal candidates for variadic element.
119 foo("", myStruct) //@complete(")", litMyStruct, litMyStructType)
123 Buffer{} //@item(litBuffer, "Buffer{}", "", "var")
126 b = bytes.Bu //@snippet(" //", litBuffer, "Buffer{\\}", "Buffer{\\}")
130 _ = "func(...) {}" //@item(litFunc, "func(...) {}", "", "var")
132 sort.Slice(nil, fun) //@complete(")", litFunc),snippet(")", litFunc, "func(i, j int) bool {$0\\}", "func(i, j int) bool {$0\\}")
134 http.HandleFunc("", f) //@snippet(")", litFunc, "func(rw http.ResponseWriter, r *http.Request) {$0\\}", "func(${1:rw} http.ResponseWriter, ${2:r} *http.Request) {$0\\}")
136 // no literal "func" completions
137 http.Handle("", fun) //@complete(")")
139 http.HandlerFunc() //@item(handlerFunc, "http.HandlerFunc()", "", "var")
140 http.Handle("", h) //@snippet(")", handlerFunc, "http.HandlerFunc($0)", "http.HandlerFunc($0)")
141 http.Handle("", http.HandlerFunc()) //@snippet("))", litFunc, "func(rw http.ResponseWriter, r *http.Request) {$0\\}", "func(${1:rw} http.ResponseWriter, ${2:r} *http.Request) {$0\\}")
143 var namedReturn func(s string) (b bool)
144 namedReturn = f //@snippet(" //", litFunc, "func(s string) (b bool) {$0\\}", "func(s string) (b bool) {$0\\}")
146 var multiReturn func() (bool, int)
147 multiReturn = f //@snippet(" //", litFunc, "func() (bool, int) {$0\\}", "func() (bool, int) {$0\\}")
149 var multiNamedReturn func() (b bool, i int)
150 multiNamedReturn = f //@snippet(" //", litFunc, "func() (b bool, i int) {$0\\}", "func() (b bool, i int) {$0\\}")
152 var duplicateParams func(myImpl, int, myImpl)
153 duplicateParams = f //@snippet(" //", litFunc, "func(mi1 myImpl, i int, mi2 myImpl) {$0\\}", "func(${1:mi1} myImpl, ${2:i} int, ${3:mi2} myImpl) {$0\\}")
155 type aliasImpl = myImpl
156 var aliasParams func(aliasImpl) aliasImpl
157 aliasParams = f //@snippet(" //", litFunc, "func(ai aliasImpl) aliasImpl {$0\\}", "func(${1:ai} aliasImpl) aliasImpl {$0\\}")
160 var builtinTypes func([]int, [two]bool, map[string]string, struct{ i int }, interface{ foo() }, <-chan int)
161 builtinTypes = f //@snippet(" //", litFunc, "func(i1 []int, b [two]bool, m map[string]string, s struct{ i int \\}, i2 interface{ foo() \\}, c <-chan int) {$0\\}", "func(${1:i1} []int, ${2:b} [two]bool, ${3:m} map[string]string, ${4:s} struct{ i int \\}, ${5:i2} interface{ foo() \\}, ${6:c} <-chan int) {$0\\}")
165 StructFoo{} //@item(litStructFoo, "StructFoo{}", "struct{...}", "struct")
167 var sfp *foo.StructFoo
168 // Don't insert the "&" before "StructFoo{}".
169 sfp = foo.Str //@snippet(" //", litStructFoo, "StructFoo{$0\\}", "StructFoo{$0\\}")
172 sf = foo.Str //@snippet(" //", litStructFoo, "StructFoo{$0\\}", "StructFoo{$0\\}")
173 sf = foo. //@snippet(" //", litStructFoo, "StructFoo{$0\\}", "StructFoo{$0\\}")
177 float64() //@item(litFloat64, "float64()", "float64", "var")
179 // don't complete to "&float64()"
180 var _ *float64 = float64 //@complete(" //")
183 f = fl //@complete(" //", litFloat64),snippet(" //", litFloat64, "float64($0)", "float64($0)")
186 myInt() //@item(litMyInt, "myInt()", "", "var")
189 mi = my //@snippet(" //", litMyInt, "myInt($0)", "myInt($0)")
193 type ptrStruct struct {
197 ptrStruct{} //@item(litPtrStruct, "ptrStruct{}", "", "var")
200 p: &ptrSt, //@rank(",", litPtrStruct)
203 &ptrStruct{} //@item(litPtrStructPtr, "&ptrStruct{}", "", "var")
206 p: ptrSt, //@rank(",", litPtrStructPtr)
211 f := func(...[]int) {}
212 f() //@snippet(")", litIntSlice, "[]int{$0\\}", "[]int{$0\\}")