1
0
mirror of https://github.com/golang/go synced 2024-11-19 06:04:39 -07:00
go/internal/lsp/testdata/snippets/snippets.go.in
Rebecca Stambler cc15fab314 internal/lsp: use AST to construct placeholders
Type aliases don't work well with types.TypeString. Work around that by
using the AST to build this information. Follow up from CL 201677.

Fixes golang/go#33500

Change-Id: I8b2d4ea238eb5d284a419f2b0bbf9655e69d434d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208497
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-11-25 01:11:57 +00:00

54 lines
2.1 KiB
Go

package snippets
type AliasType = int //@item(sigAliasType, "AliasType", "AliasType", "type")
func foo(i int, b bool) {} //@item(snipFoo, "foo", "func(i int, b bool)", "func")
func bar(fn func()) func() {} //@item(snipBar, "bar", "func(fn func())", "func")
func baz(at AliasType, b bool) {} //@item(snipBaz, "baz", "func(at AliasType, b bool)", "func")
type Foo struct {
Bar int //@item(snipFieldBar, "Bar", "int", "field")
Func func(at AliasType) error //@item(snipFieldFunc, "Func", "func(at AliasType) error", "field")
}
func (Foo) Baz() func() {} //@item(snipMethodBaz, "Baz", "func() func()", "method")
func (Foo) BazBar() func() {} //@item(snipMethodBazBar, "BazBar", "func() func()", "method")
func (Foo) BazBaz(at AliasType) func() {} //@item(snipMethodBazBaz, "BazBaz", "func(at AliasType) func()", "method")
func _() {
f //@snippet(" //", snipFoo, "foo(${1:})", "foo(${1:i int}, ${2:b bool})")
bar //@snippet(" //", snipBar, "bar(${1:})", "bar(${1:fn func()})")
baz //@snippet(" //", snipBaz, "baz(${1:})", "baz(${1:at AliasType}, ${2:b bool})")
baz() //@signature("(", "baz(at AliasType, b bool)", 0)
bar(nil) //@snippet("(", snipBar, "bar", "bar")
bar(ba) //@snippet(")", snipBar, "bar(${1:})", "bar(${1:fn func()})")
var f Foo
bar(f.Ba) //@snippet(")", snipMethodBaz, "Baz()", "Baz()")
(bar)(nil) //@snippet(")", snipBar, "bar(${1:})", "bar(${1:fn func()})")
(f.Ba)() //@snippet(")", snipMethodBaz, "Baz()", "Baz()")
Foo{
B //@snippet(" //", snipFieldBar, "Bar: ${1:},", "Bar: ${1:int},")
}
Foo{
F //@snippet(" //", snipFieldFunc, "Func: ${1:},", "Func: ${1:func(at AliasType) error},")
}
Foo{B} //@snippet("}", snipFieldBar, "Bar: ${1:}", "Bar: ${1:int}")
Foo{} //@snippet("}", snipFieldBar, "Bar: ${1:}", "Bar: ${1:int}")
Foo{Foo{}.B} //@snippet("} ", snipFieldBar, "Bar", "Bar")
var err error
err.Error() //@snippet("E", Error, "Error()", "Error()")
f.Baz() //@snippet("B", snipMethodBaz, "Baz()", "Baz()")
f.Baz() //@snippet("(", snipMethodBazBar, "BazBar", "BazBar")
f.Baz() //@snippet("B", snipMethodBazBaz, "BazBaz(${1:})", "BazBaz(${1:at AliasType})")
}