internal/lsp/source: fix type modifier detection in composite literals

When completing a composite literal value, we were returning from
candidate inference before we recorded type modifiers such as prefix
"&" or "*". This was causing funny completions like:

type myStruct struct { s *myStruct }
myStruct{s: &mySt<> // completed to "&&myStruct{}"

Now we properly pick up on the "&" prefix so we know our literal
"myStruct{}" candidate does not need a "&".

Change-Id: I908936698cfedfef81bc0c1cbcd93e14dc00e3a3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/218377
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:
Muir Manders 2020-02-06 20:33:22 -08:00 committed by Rebecca Stambler
parent 8feddd8b6a
commit 1e13d9580f
2 changed files with 12 additions and 1 deletions

View File

@ -1329,7 +1329,6 @@ func expectedCandidate(c *completer) (inf candidateInference) {
if c.enclosingCompositeLiteral != nil {
inf.objType = c.expectedCompositeLiteralType()
return inf
}
Nodes:

View File

@ -180,3 +180,15 @@ func _() {
var mi myInt
mi = my //@snippet(" //", litMyInt, "myInt($0)", "myInt($0)")
}
func _() {
type ptrStruct struct {
p *ptrStruct
}
ptrStruct{} //@item(litPtrStruct, "ptrStruct{}", "", "var")
ptrStruct{
p: &ptrSt, //@rank(",", litPtrStruct)
}
}