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