diff --git a/internal/lsp/source/completion.go b/internal/lsp/source/completion.go index e103e26018..41830f08fa 100644 --- a/internal/lsp/source/completion.go +++ b/internal/lsp/source/completion.go @@ -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) } 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 ffaa125073..69b8cdf173 100644 --- a/internal/lsp/testdata/lsp/primarymod/snippets/literal_snippets.go.in +++ b/internal/lsp/testdata/lsp/primarymod/snippets/literal_snippets.go.in @@ -192,3 +192,8 @@ func _() { p: &ptrSt, //@rank(",", litPtrStruct) } } + +func _() { + f := func(...[]int) {} + f() //@snippet(")", litIntSlice, "[]int{$0\\}", "[]int{$0\\}") +} diff --git a/internal/lsp/testdata/lsp/summary.txt.golden b/internal/lsp/testdata/lsp/summary.txt.golden index 9dc1e2a52d..b7bdc3bafc 100644 --- a/internal/lsp/testdata/lsp/summary.txt.golden +++ b/internal/lsp/testdata/lsp/summary.txt.golden @@ -1,7 +1,7 @@ -- summary -- CodeLensCount = 2 CompletionsCount = 237 -CompletionSnippetCount = 74 +CompletionSnippetCount = 75 UnimportedCompletionsCount = 11 DeepCompletionsCount = 5 FuzzyCompletionsCount = 8