.gitignore added
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools@v0.1.0 / internal / lsp / testdata / snippets / literal_snippets.go.in
1 package snippets
2
3 import (
4         "bytes"
5         "go/ast"
6         "net/http"
7         "sort"
8
9         "golang.org/x/tools/internal/lsp/foo"
10 )
11
12 func _() {
13         []int{}        //@item(litIntSlice, "[]int{}", "", "var")
14         &[]int{}       //@item(litIntSliceAddr, "&[]int{}", "", "var")
15         make([]int, 0) //@item(makeIntSlice, "make([]int, 0)", "", "func")
16
17         var _ *[]int = in //@snippet(" //", litIntSliceAddr, "&[]int{$0\\}", "&[]int{$0\\}")
18         var _ **[]int = in //@complete(" //")
19
20         var slice []int
21         slice = i //@snippet(" //", litIntSlice, "[]int{$0\\}", "[]int{$0\\}")
22         slice = m //@snippet(" //", makeIntSlice, "make([]int, ${1:})", "make([]int, ${1:0})")
23 }
24
25 func _() {
26         type namedInt []int
27
28         namedInt{}        //@item(litNamedSlice, "namedInt{}", "", "var")
29         make(namedInt, 0) //@item(makeNamedSlice, "make(namedInt, 0)", "", "func")
30
31         var namedSlice namedInt
32         namedSlice = n //@snippet(" //", litNamedSlice, "namedInt{$0\\}", "namedInt{$0\\}")
33         namedSlice = m //@snippet(" //", makeNamedSlice, "make(namedInt, ${1:})", "make(namedInt, ${1:0})")
34 }
35
36 func _() {
37         make(chan int) //@item(makeChan, "make(chan int)", "", "func")
38
39         var ch chan int
40         ch = m //@snippet(" //", makeChan, "make(chan int)", "make(chan int)")
41 }
42
43 func _() {
44         map[string]struct{}{}     //@item(litMap, "map[string]struct{}{}", "", "var")
45         make(map[string]struct{}) //@item(makeMap, "make(map[string]struct{})", "", "func")
46
47         var m map[string]struct{}
48         m = m //@snippet(" //", litMap, "map[string]struct{\\}{$0\\}", "map[string]struct{\\}{$0\\}")
49         m = m //@snippet(" //", makeMap, "make(map[string]struct{\\})", "make(map[string]struct{\\})")
50
51         struct{}{} //@item(litEmptyStruct, "struct{}{}", "", "var")
52
53         m["hi"] = s //@snippet(" //", litEmptyStruct, "struct{\\}{\\}", "struct{\\}{\\}")
54 }
55
56 func _() {
57         type myStruct struct{ i int }
58
59         myStruct{}  //@item(litStruct, "myStruct{}", "", "var")
60         &myStruct{} //@item(litStructPtr, "&myStruct{}", "", "var")
61
62         var ms myStruct
63         ms = m //@snippet(" //", litStruct, "myStruct{$0\\}", "myStruct{$0\\}")
64
65         var msPtr *myStruct
66         msPtr = m //@snippet(" //", litStructPtr, "&myStruct{$0\\}", "&myStruct{$0\\}")
67
68         msPtr = &m //@snippet(" //", litStruct, "myStruct{$0\\}", "myStruct{$0\\}")
69 }
70
71 type myImpl struct{}
72
73 func (myImpl) foo() {}
74
75 func (*myImpl) bar() {}
76
77 type myBasicImpl string
78
79 func (myBasicImpl) foo() {}
80
81 func _() {
82         type myIntf interface {
83                 foo()
84         }
85
86         myImpl{} //@item(litImpl, "myImpl{}", "", "var")
87
88         var mi myIntf
89         mi = m //@snippet(" //", litImpl, "myImpl{\\}", "myImpl{\\}")
90
91         myBasicImpl() //@item(litBasicImpl, "myBasicImpl()", "string", "var")
92
93         mi = m //@snippet(" //", litBasicImpl, "myBasicImpl($0)", "myBasicImpl($0)")
94
95         // only satisfied by pointer to myImpl
96         type myPtrIntf interface {
97                 bar()
98         }
99
100         &myImpl{} //@item(litImplPtr, "&myImpl{}", "", "var")
101
102         var mpi myPtrIntf
103         mpi = m //@snippet(" //", litImplPtr, "&myImpl{\\}", "&myImpl{\\}")
104 }
105
106 func _() {
107         var s struct{ i []int } //@item(litSliceField, "i", "[]int", "field")
108         var foo []int
109         // no literal completions after selector
110         foo = s.i //@complete(" //", litSliceField)
111 }
112
113 func _() {
114         type myStruct struct{ i int } //@item(litMyStructType, "myStruct", "struct{...}", "struct")
115         myStruct{} //@item(litMyStruct, "myStruct{}", "", "var")
116
117         foo := func(s string, args ...myStruct) {}
118         // Don't give literal slice candidate for variadic arg.
119         // Do give literal candidates for variadic element.
120         foo("", myStruct) //@complete(")", litMyStruct, litMyStructType)
121 }
122
123 func _() {
124         Buffer{} //@item(litBuffer, "Buffer{}", "", "var")
125
126         var b *bytes.Buffer
127         b = bytes.Bu //@snippet(" //", litBuffer, "Buffer{\\}", "Buffer{\\}")
128 }
129
130 func _() {
131         _ = "func(...) {}" //@item(litFunc, "func(...) {}", "", "var")
132
133         sort.Slice(nil, fun) //@complete(")", litFunc),snippet(")", litFunc, "func(i, j int) bool {$0\\}", "func(i, j int) bool {$0\\}")
134
135         http.HandleFunc("", f) //@snippet(")", litFunc, "func(rw http.ResponseWriter, r *http.Request) {$0\\}", "func(${1:rw} http.ResponseWriter, ${2:r} *http.Request) {$0\\}")
136
137         // no literal "func" completions
138         http.Handle("", fun) //@complete(")")
139
140         http.HandlerFunc() //@item(handlerFunc, "http.HandlerFunc()", "", "var")
141         http.Handle("", h) //@snippet(")", handlerFunc, "http.HandlerFunc($0)", "http.HandlerFunc($0)")
142         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
144         var namedReturn func(s string) (b bool)
145         namedReturn = f //@snippet(" //", litFunc, "func(s string) (b bool) {$0\\}", "func(s string) (b bool) {$0\\}")
146
147         var multiReturn func() (bool, int)
148         multiReturn = f //@snippet(" //", litFunc, "func() (bool, int) {$0\\}", "func() (bool, int) {$0\\}")
149
150         var multiNamedReturn func() (b bool, i int)
151         multiNamedReturn = f //@snippet(" //", litFunc, "func() (b bool, i int) {$0\\}", "func() (b bool, i int) {$0\\}")
152
153         var duplicateParams func(myImpl, int, myImpl)
154         duplicateParams = f //@snippet(" //", litFunc, "func(mi1 myImpl, i int, mi2 myImpl) {$0\\}", "func(${1:mi1} myImpl, ${2:i} int, ${3:mi2} myImpl) {$0\\}")
155
156         type aliasImpl = myImpl
157         var aliasParams func(aliasImpl) aliasImpl
158         aliasParams = f //@snippet(" //", litFunc, "func(ai aliasImpl) aliasImpl {$0\\}", "func(${1:ai} aliasImpl) aliasImpl {$0\\}")
159
160         const two = 2
161         var builtinTypes func([]int, [two]bool, map[string]string, struct{ i int }, interface{ foo() }, <-chan int)
162         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\\}")
163
164         var _ func(ast.Node) = f //@snippet(" //", litFunc, "func(n ast.Node) {$0\\}", "func(${1:n} ast.Node) {$0\\}")
165 }
166
167 func _() {
168         StructFoo{} //@item(litStructFoo, "StructFoo{}", "struct{...}", "struct")
169
170         var sfp *foo.StructFoo
171         // Don't insert the "&" before "StructFoo{}".
172         sfp = foo.Str //@snippet(" //", litStructFoo, "StructFoo{$0\\}", "StructFoo{$0\\}")
173
174         var sf foo.StructFoo
175         sf = foo.Str //@snippet(" //", litStructFoo, "StructFoo{$0\\}", "StructFoo{$0\\}")
176         sf = foo. //@snippet(" //", litStructFoo, "StructFoo{$0\\}", "StructFoo{$0\\}")
177 }
178
179 func _() {
180         float64() //@item(litFloat64, "float64()", "float64", "var")
181
182         // don't complete to "&float64()"
183         var _ *float64 = float64 //@complete(" //")
184
185         var f float64
186         f = fl //@complete(" //", litFloat64),snippet(" //", litFloat64, "float64($0)", "float64($0)")
187
188         type myInt int
189         myInt() //@item(litMyInt, "myInt()", "", "var")
190
191         var mi myInt
192         mi = my //@snippet(" //", litMyInt, "myInt($0)", "myInt($0)")
193 }
194
195 func _() {
196         type ptrStruct struct {
197                 p *ptrStruct
198         }
199
200         ptrStruct{} //@item(litPtrStruct, "ptrStruct{}", "", "var")
201
202         ptrStruct{
203                 p: &ptrSt, //@rank(",", litPtrStruct)
204         }
205
206         &ptrStruct{} //@item(litPtrStructPtr, "&ptrStruct{}", "", "var")
207
208         &ptrStruct{
209                 p: ptrSt, //@rank(",", litPtrStructPtr)
210         }
211 }
212
213 func _() {
214         f := func(...[]int) {}
215         f() //@snippet(")", litIntSlice, "[]int{$0\\}", "[]int{$0\\}")
216 }