| 1 |
This test checks basic completion snippet support. |
| 2 |
|
| 3 |
-- flags -- |
| 4 |
-ignore_extra_diags |
| 5 |
|
| 6 |
-- go.mod -- |
| 7 |
module golang.org/lsptests/snippet |
| 8 |
|
| 9 |
-- snippet.go -- |
| 10 |
package snippets |
| 11 |
|
| 12 |
// Pre-set this marker, as we don't have a "source" for it in this package. |
| 13 |
// The comment is used to create a synthetic completion item. |
| 14 |
// |
| 15 |
// TODO(rfindley): allow completion markers to refer to ad-hoc items inline, |
| 16 |
// without this trick. |
| 17 |
/* Error() */ //@item(Error, "Error", "func() string", "method") |
| 18 |
|
| 19 |
type AliasType = int //@item(sigAliasType, "AliasType", "AliasType", "type") |
| 20 |
|
| 21 |
func foo(i int, b bool) {} //@item(snipFoo, "foo", "func(i int, b bool)", "func") |
| 22 |
func bar(fn func()) func() {} //@item(snipBar, "bar", "func(fn func())", "func") |
| 23 |
func baz(at AliasType, b bool) {} //@item(snipBaz, "baz", "func(at AliasType, b bool)", "func") |
| 24 |
|
| 25 |
type Foo struct { |
| 26 |
Bar int //@item(snipFieldBar, "Bar", "int", "field") |
| 27 |
Func func(at AliasType) error //@item(snipFieldFunc, "Func", "func(at AliasType) error", "field") |
| 28 |
} |
| 29 |
|
| 30 |
func (Foo) Baz() func() {} //@item(snipMethodBaz, "Baz", "func() func()", "method") |
| 31 |
func (Foo) BazBar() func() {} //@item(snipMethodBazBar, "BazBar", "func() func()", "method") |
| 32 |
func (Foo) BazBaz(at AliasType) func() {} //@item(snipMethodBazBaz, "BazBaz", "func(at AliasType) func()", "method") |
| 33 |
|
| 34 |
func _() { |
| 35 |
f //@snippet(re"() \\/\\/", snipFoo, "foo(${1:})") |
| 36 |
|
| 37 |
bar //@snippet(re"() \\/\\/", snipBar, "bar(${1:})") |
| 38 |
|
| 39 |
baz() //@snippet(re"()\\(", snipBaz, "baz") |
| 40 |
|
| 41 |
bar(nil) //@snippet(re"()\\(", snipBar, "bar") |
| 42 |
bar(ba) //@snippet(re"()\\)", snipBar, "bar(${1:})") |
| 43 |
var f Foo |
| 44 |
bar(f.Ba) //@snippet(re"()\\)", snipMethodBaz, "Baz()") |
| 45 |
(bar)(nil) //@snippet(re"()\\)", snipBar, "bar(${1:})") |
| 46 |
(f.Ba)() //@snippet(re"()\\)", snipMethodBaz, "Baz()") |
| 47 |
|
| 48 |
Foo{ |
| 49 |
B //@snippet(re"() \\/\\/", snipFieldBar, "Bar: ${1:},") |
| 50 |
} |
| 51 |
|
| 52 |
Foo{ |
| 53 |
F //@snippet(re"() \\/\\/", snipFieldFunc, "Func: ${1:},") |
| 54 |
} |
| 55 |
|
| 56 |
Foo{B} //@snippet(re"()}", snipFieldBar, "Bar: ${1:}") |
| 57 |
Foo{} //@snippet(re"()}", snipFieldBar, "Bar: ${1:}") |
| 58 |
|
| 59 |
Foo{Foo{}.B} //@snippet(re"()} ", snipFieldBar, "Bar") |
| 60 |
|
| 61 |
var err error |
| 62 |
err.Error() //@snippet(re"()E", Error, "Error()") |
| 63 |
f.Baz() //@snippet(re"()B", snipMethodBaz, "Baz()") |
| 64 |
|
| 65 |
f.Baz() //@snippet(re"()\\(", snipMethodBazBar, "BazBar") |
| 66 |
|
| 67 |
f.Baz() //@snippet(re"()B", snipMethodBazBaz, "BazBaz(${1:})") |
| 68 |
} |
| 69 |
|
| 70 |
func _() { |
| 71 |
type bar struct { |
| 72 |
a int |
| 73 |
b float64 //@item(snipBarB, "b", "float64") |
| 74 |
} |
| 75 |
bar{b} //@snippet(re"()}", snipBarB, "b: ${1:}") |
| 76 |
} |