internal/lsp/source: fix multi return value func completion

Fix a minor completion ranking issue:

    foo := func(int, int) {}
    foo(123, <>)

Previously we were preferring "foo()" at "<>" even though it can't be
used. We mistakenly thought we were completing the first param because
the *ast.CallExpr appears to only have a single param.

Change-Id: Iedbbb1870a4b9eb5d5be4ed266b8bb3e313b496b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/246697
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-08-03 11:36:03 -07:00 committed by Rebecca Stambler
parent 0b898c9289
commit 6fe4996ff4
3 changed files with 3 additions and 2 deletions

View File

@ -1661,7 +1661,7 @@ Nodes:
// values, in turn getting passed in to the surrounding
// call. Record the assignees so we can favor function
// calls that return matching values.
if len(node.Args) <= 1 {
if len(node.Args) <= 1 && exprIdx == 0 {
for i := 0; i < sig.Params().Len(); i++ {
inf.assignees = append(inf.assignees, sig.Params().At(i).Type())
}

View File

@ -23,6 +23,7 @@ func _() {
f1(f) //@rank(")", multiF1, multiF2)
f2(f) //@rank(")", multiF2, multiF3),rank(")", multiF1, multiF3)
f2(1, f) //@rank(")", multiF1, multiF2),rank(")", multiF1, multiF0)
f2(1, ) //@rank(")", multiF1, multiF2),rank(")", multiF1, multiF0)
f2Str() //@rank(")", multiF2Str, multiF2)
var i int

View File

@ -5,7 +5,7 @@ CompletionSnippetCount = 80
UnimportedCompletionsCount = 6
DeepCompletionsCount = 5
FuzzyCompletionsCount = 8
RankedCompletionsCount = 120
RankedCompletionsCount = 122
CaseSensitiveCompletionsCount = 4
DiagnosticsCount = 44
FoldingRangesCount = 2