| 1 |
This test checks basic completion snippet support, using placeholders. |
| 2 |
|
| 3 |
Unlike the old marker tests, the new marker tests assume static configuration |
| 4 |
(as defined by settings.json), and therefore there is duplication between this |
| 5 |
test and snippet.txt. This is a price we pay so that we don't have to mutate |
| 6 |
the server during testing. |
| 7 |
|
| 8 |
-- flags -- |
| 9 |
-ignore_extra_diags |
| 10 |
|
| 11 |
-- settings.json -- |
| 12 |
{ |
| 13 |
"usePlaceholders": true |
| 14 |
} |
| 15 |
|
| 16 |
-- go.mod -- |
| 17 |
module golang.org/lsptests/snippet |
| 18 |
|
| 19 |
-- snippet.go -- |
| 20 |
package snippets |
| 21 |
|
| 22 |
// Pre-set this marker, as we don't have a "source" for it in this package. |
| 23 |
/* Error() */ //@item(Error, "Error", "func() string", "method") |
| 24 |
|
| 25 |
type AliasType = int //@item(sigAliasType, "AliasType", "AliasType", "type") |
| 26 |
|
| 27 |
func foo(i int, b bool) {} //@item(snipFoo, "foo", "func(i int, b bool)", "func") |
| 28 |
func bar(fn func()) func() {} //@item(snipBar, "bar", "func(fn func())", "func") |
| 29 |
func baz(at AliasType, b bool) {} //@item(snipBaz, "baz", "func(at AliasType, b bool)", "func") |
| 30 |
|
| 31 |
type Foo struct { |
| 32 |
Bar int //@item(snipFieldBar, "Bar", "int", "field") |
| 33 |
Func func(at AliasType) error //@item(snipFieldFunc, "Func", "func(at AliasType) error", "field") |
| 34 |
} |
| 35 |
|
| 36 |
func (Foo) Baz() func() {} //@item(snipMethodBaz, "Baz", "func() func()", "method") |
| 37 |
func (Foo) BazBar() func() {} //@item(snipMethodBazBar, "BazBar", "func() func()", "method") |
| 38 |
func (Foo) BazBaz(at AliasType) func() {} //@item(snipMethodBazBaz, "BazBaz", "func(at AliasType) func()", "method") |
| 39 |
|
| 40 |
func _() { |
| 41 |
f //@snippet(re"() \\/\\/", snipFoo, "foo(${1:i int}, ${2:b bool})") |
| 42 |
|
| 43 |
bar //@snippet(re"() \\/\\/", snipBar, "bar(${1:fn func()})") |
| 44 |
|
| 45 |
baz //@snippet(re"() \\/\\/", snipBaz, "baz(${1:at AliasType}, ${2:b bool})") |
| 46 |
|
| 47 |
bar(nil) //@snippet(re"()\\(", snipBar, "bar") |
| 48 |
bar(ba) //@snippet(re"()\\)", snipBar, "bar(${1:fn func()})") |
| 49 |
var f Foo |
| 50 |
bar(f.Ba) //@snippet(re"()\\)", snipMethodBaz, "Baz()") |
| 51 |
(bar)(nil) //@snippet(re"()\\)", snipBar, "bar(${1:fn func()})") |
| 52 |
(f.Ba)() //@snippet(re"()\\)", snipMethodBaz, "Baz()") |
| 53 |
|
| 54 |
Foo{ |
| 55 |
B //@snippet(re"() \\/\\/", snipFieldBar, "Bar: ${1:int},") |
| 56 |
} |
| 57 |
|
| 58 |
Foo{ |
| 59 |
F //@snippet(re"() \\/\\/", snipFieldFunc, "Func: ${1:func(at AliasType) error},") |
| 60 |
} |
| 61 |
|
| 62 |
Foo{B} //@snippet(re"()}", snipFieldBar, "Bar: ${1:int}") |
| 63 |
Foo{} //@snippet(re"()}", snipFieldBar, "Bar: ${1:int}") |
| 64 |
|
| 65 |
Foo{Foo{}.B} //@snippet(re"()} ", snipFieldBar, "Bar") |
| 66 |
|
| 67 |
var err error |
| 68 |
err.Error() //@snippet(re"()E", Error, "Error()") |
| 69 |
f.Baz() //@snippet(re"()B", snipMethodBaz, "Baz()") |
| 70 |
|
| 71 |
f.Baz() //@snippet(re"()\\(", snipMethodBazBar, "BazBar") |
| 72 |
|
| 73 |
f.Baz() //@snippet(re"()B", snipMethodBazBaz, "BazBaz(${1:at AliasType})") |
| 74 |
} |
| 75 |
|
| 76 |
func _() { |
| 77 |
type bar struct { |
| 78 |
a int |
| 79 |
b float64 //@item(snipBarB, "b", "field") |
| 80 |
} |
| 81 |
bar{b} //@snippet(re"()}", snipBarB, "b: ${1:float64}") |
| 82 |
} |