mirror of https://github.com/golang/go.git
internal/lsp/source: fix literal completions in variadic args
We now properly offer literal completions when completing the variadic
parameter. For example:
func foo(...[]int) {}
foo(<>) // now offers "[]int{}"
Updates golang/go#37656.
Change-Id: I91c47d455ae3f8051078c82a308f2b5ad4b3d4cd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222199
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
613a0345a2
commit
11a475a590
|
|
@ -1052,12 +1052,18 @@ func (c *completer) lexical() error {
|
|||
}
|
||||
}
|
||||
|
||||
if c.inference.objType != nil {
|
||||
if t := c.inference.objType; t != nil {
|
||||
// Use variadic element type if we are completing variadic position.
|
||||
if c.inference.variadicType != nil {
|
||||
t = c.inference.variadicType
|
||||
}
|
||||
|
||||
t = deref(t)
|
||||
|
||||
// If we have an expected type and it is _not_ a named type, see
|
||||
// if an object literal makes a good candidate. For example, if
|
||||
// our expected type is "[]int", this will add a candidate of
|
||||
// "[]int{}".
|
||||
t := deref(c.inference.objType)
|
||||
if _, named := t.(*types.Named); !named {
|
||||
c.literal(t, nil)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -192,3 +192,8 @@ func _() {
|
|||
p: &ptrSt, //@rank(",", litPtrStruct)
|
||||
}
|
||||
}
|
||||
|
||||
func _() {
|
||||
f := func(...[]int) {}
|
||||
f() //@snippet(")", litIntSlice, "[]int{$0\\}", "[]int{$0\\}")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
-- summary --
|
||||
CodeLensCount = 2
|
||||
CompletionsCount = 237
|
||||
CompletionSnippetCount = 74
|
||||
CompletionSnippetCount = 75
|
||||
UnimportedCompletionsCount = 11
|
||||
DeepCompletionsCount = 5
|
||||
FuzzyCompletionsCount = 8
|
||||
|
|
|
|||
Loading…
Reference in New Issue