mirror of
https://github.com/golang/go
synced 2024-11-19 02:44:44 -07:00
dd2b5c81c5
I moved the "usePlaceholders" config field on to CompletionOptions. This way the completion code generates a single snippet with a little conditional logic based on the "WantPlaceholders" option instead of juggling the generation of two almost identical "plain" and "placeholder" snippets at the same time. It also reduces the work done generating completion candidates a little. I also made a minor tweak to the snippet builder where empty placeholders are now always represented as e.g "${1:}" instead of "${1}" or "${1:}", depending on if you passed a callback to WritePlaceholder() or not. Change-Id: Ib84cc0cd729a11b9e13ad3ac4b6fd2d82460acd5 Reviewed-on: https://go-review.googlesource.com/c/tools/+/193697 Reviewed-by: Rebecca Stambler <rstambler@golang.org> Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
40 lines
1.4 KiB
Go
40 lines
1.4 KiB
Go
package snippets
|
|
|
|
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")
|
|
|
|
type Foo struct {
|
|
Bar int //@item(snipFieldBar, "Bar", "int", "field")
|
|
}
|
|
|
|
func (Foo) Baz() func() {} //@item(snipMethodBaz, "Baz", "func() func()", "method")
|
|
func (Foo) BazBar() func() {} //@item(snipMethodBazBar, "BazBar", "func() func()", "method")
|
|
|
|
func _() {
|
|
f //@snippet(" //", snipFoo, "foo(${1:})", "foo(${1:i int}, ${2:b bool})")
|
|
|
|
bar //@snippet(" //", snipBar, "bar(${1:})", "bar(${1:fn func()})")
|
|
|
|
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{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")
|
|
}
|