From 1e13d9580f8baff99f7d0302f84d2ffd0c0dcf73 Mon Sep 17 00:00:00 2001 From: Muir Manders Date: Thu, 6 Feb 2020 20:33:22 -0800 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Rebecca Stambler --- internal/lsp/source/completion.go | 1 - .../lsp/primarymod/snippets/literal_snippets.go.in | 12 ++++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/internal/lsp/source/completion.go b/internal/lsp/source/completion.go index eb8d18d2b1..b6193c5728 100644 --- a/internal/lsp/source/completion.go +++ b/internal/lsp/source/completion.go @@ -1329,7 +1329,6 @@ func expectedCandidate(c *completer) (inf candidateInference) { if c.enclosingCompositeLiteral != nil { inf.objType = c.expectedCompositeLiteralType() - return inf } Nodes: diff --git a/internal/lsp/testdata/lsp/primarymod/snippets/literal_snippets.go.in b/internal/lsp/testdata/lsp/primarymod/snippets/literal_snippets.go.in index 9906a2b78a..ffaa125073 100644 --- a/internal/lsp/testdata/lsp/primarymod/snippets/literal_snippets.go.in +++ b/internal/lsp/testdata/lsp/primarymod/snippets/literal_snippets.go.in @@ -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) + } +}