Skip to content

Commit bcb2d7b

Browse files
mattheusvstamblerre
authored andcommitted
internal/lsp: fix bad completion for variadic functions
Add variadic completion in functions only if snippets is enabled. Fixes golang/go#42691 Change-Id: I0aebe86b5a58d2f7491f0b340ad14b15c184eeb1 GitHub-Last-Rev: 04b2ad0 GitHub-Pull-Request: #280 Reviewed-on: https://go-review.googlesource.com/c/tools/+/295950 Reviewed-by: Rebecca Stambler <[email protected]> Trust: Rebecca Stambler <[email protected]> Trust: Hyang-Ah Hana Kim <[email protected]> Run-TryBot: Rebecca Stambler <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent 7ee2955 commit bcb2d7b

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

internal/lsp/source/completion/completion.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ type completionOptions struct {
9595
fullDocumentation bool
9696
placeholders bool
9797
literal bool
98+
snippets bool
9899
matcher source.Matcher
99100
budget time.Duration
100101
}
@@ -519,6 +520,7 @@ func Completion(ctx context.Context, snapshot source.Snapshot, fh source.FileHan
519520
placeholders: opts.UsePlaceholders,
520521
literal: opts.LiteralCompletions && opts.InsertTextFormat == protocol.SnippetTextFormat,
521522
budget: opts.CompletionBudget,
523+
snippets: opts.InsertTextFormat == protocol.SnippetTextFormat,
522524
},
523525
// default to a matcher that always matches
524526
matcher: prefixMatcher(""),

internal/lsp/source/completion/format.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,8 @@ func (c *completer) item(ctx context.Context, cand candidate) (CompletionItem, e
150150
prefix = typeName + "(" + prefix
151151
suffix = ")"
152152
}
153-
154-
// Add variadic "..." if we are filling in a variadic param.
155-
if cand.variadic {
153+
// Add variadic "..." only if snippets if enabled or cand is not a function
154+
if cand.variadic && (c.opts.snippets || !cand.expandFuncCall) {
156155
suffix += "..."
157156
}
158157

0 commit comments

Comments
 (0)