golang.org/x/tools/gopls@v0.15.3/internal/test/marker/testdata/completion/snippet_placeholder.txt (about) 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(" //", snipFoo, "foo(${1:i int}, ${2:b bool})") 42 43 bar //@snippet(" //", snipBar, "bar(${1:fn func()})") 44 45 baz //@snippet(" //", snipBaz, "baz(${1:at AliasType}, ${2:b bool})") 46 baz() //@signature("(", "baz(at AliasType, b bool)", 0) 47 48 bar(nil) //@snippet("(", snipBar, "bar") 49 bar(ba) //@snippet(")", snipBar, "bar(${1:fn func()})") 50 var f Foo 51 bar(f.Ba) //@snippet(")", snipMethodBaz, "Baz()") 52 (bar)(nil) //@snippet(")", snipBar, "bar(${1:fn func()})") 53 (f.Ba)() //@snippet(")", snipMethodBaz, "Baz()") 54 55 Foo{ 56 B //@snippet(" //", snipFieldBar, "Bar: ${1:int},") 57 } 58 59 Foo{ 60 F //@snippet(" //", snipFieldFunc, "Func: ${1:func(at AliasType) error},") 61 } 62 63 Foo{B} //@snippet("}", snipFieldBar, "Bar: ${1:int}") 64 Foo{} //@snippet("}", snipFieldBar, "Bar: ${1:int}") 65 66 Foo{Foo{}.B} //@snippet("} ", snipFieldBar, "Bar") 67 68 var err error 69 err.Error() //@snippet("E", Error, "Error()") 70 f.Baz() //@snippet("B", snipMethodBaz, "Baz()") 71 72 f.Baz() //@snippet("(", snipMethodBazBar, "BazBar") 73 74 f.Baz() //@snippet("B", snipMethodBazBaz, "BazBaz(${1:at AliasType})") 75 } 76 77 func _() { 78 type bar struct { 79 a int 80 b float64 //@item(snipBarB, "b", "field") 81 } 82 bar{b} //@snippet("}", snipBarB, "b: ${1:float64}") 83 }