mirror of
https://github.com/golang/go
synced 2024-11-19 03:04:42 -07:00
c07e1c6ef6
Improve candidate ranking when completing the variadic parameter of function calls. Using the example: func foo(strs ...string) {} - When completing foo(<>), we prefer candidates of type []string or string (previously we only preferred []string). - When completing foo("hi", <>), we prefer candidates of type string (previously we preferred []string). - When completing foo(<>), we use a snippet to add on the "..." automatically to candidates of type []string. I also fixed completion tests to work properly when you have multiple notes referring to the same position. For example: foo() //@rank(")", a, b),rank(")", a, c) Previously the second "rank" was silently overwriting the first because they both refer to the same ")". Fixes golang/go#34334. Change-Id: I4f64be44a4ccbb533fb7682738c759cbca3a93cd Reviewed-on: https://go-review.googlesource.com/c/tools/+/205117 Reviewed-by: Rebecca Stambler <rstambler@golang.org> Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
24 lines
763 B
Go
24 lines
763 B
Go
package variadic
|
|
|
|
func foo(i int, strs ...string) {}
|
|
|
|
func bar() []string { //@item(vFunc, "bar", "func() []string", "func")
|
|
return nil
|
|
}
|
|
|
|
func _() {
|
|
var (
|
|
i int //@item(vInt, "i", "int", "var")
|
|
s string //@item(vStr, "s", "string", "var")
|
|
ss []string //@item(vStrSlice, "ss", "[]string", "var")
|
|
)
|
|
|
|
foo() //@rank(")", vInt, vStr),rank(")", vInt, vStrSlice)
|
|
foo(123, ) //@rank(")", vStr, vInt),rank(")", vStrSlice, vInt)
|
|
foo(123, "", ) //@rank(")", vStr, vInt),rank(")", vStr, vStrSlice)
|
|
foo(123, , "") //@rank(" ,", vStr, vInt),rank(")", vStr, vStrSlice)
|
|
|
|
// snippet will add the "..." for you
|
|
foo(123, ) //@snippet(")", vStrSlice, "ss...", "ss..."),snippet(")", vFunc, "bar()...", "bar()..."),snippet(")", vStr, "s", "s")
|
|
}
|