mirror of https://github.com/golang/go.git
internal/lsp: disable literal completion candidates for some clients
If a client doesn't support the snippet format in completion insert text, they can't take full advantage of the literal completion candidates. Disable it in those cases, and remove the setting in internal/lsp/source/options.go. Fixes golang/go#36655. Change-Id: Ibc045a0f2945aab753b0187194a03d0c0398dba5 Reviewed-on: https://go-review.googlesource.com/c/tools/+/216299 Run-TryBot: Rebecca Stambler <rstambler@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com>
This commit is contained in:
parent
3f4d10fc73
commit
1b668f2091
|
|
@ -14,8 +14,14 @@ func (r *runner) Completion(t *testing.T, src span.Span, test tests.Completion,
|
|||
got := r.callCompletion(t, src, func(opts *source.Options) {
|
||||
opts.DeepCompletion = false
|
||||
opts.Matcher = source.CaseInsensitive
|
||||
opts.Literal = strings.Contains(string(src.URI()), "literal")
|
||||
opts.UnimportedCompletion = false
|
||||
opts.InsertTextFormat = protocol.PlainTextTextFormat
|
||||
// Only enable literal completions if in the completion literals tests.
|
||||
// TODO(rstambler): Separate out literal completion tests.
|
||||
if strings.Contains(string(src.URI()), "literal") {
|
||||
opts.InsertTextFormat = protocol.SnippetTextFormat
|
||||
}
|
||||
|
||||
})
|
||||
if !strings.Contains(string(src.URI()), "builtins") {
|
||||
got = tests.FilterBuiltins(got)
|
||||
|
|
@ -31,7 +37,6 @@ func (r *runner) CompletionSnippet(t *testing.T, src span.Span, expected tests.C
|
|||
opts.Placeholders = placeholders
|
||||
opts.DeepCompletion = true
|
||||
opts.Matcher = source.Fuzzy
|
||||
opts.Literal = true
|
||||
opts.UnimportedCompletion = false
|
||||
})
|
||||
got := tests.FindItem(list, *items[expected.CompletionItem])
|
||||
|
|
@ -103,7 +108,6 @@ func (r *runner) RankCompletion(t *testing.T, src span.Span, test tests.Completi
|
|||
got := r.callCompletion(t, src, func(opts *source.Options) {
|
||||
opts.DeepCompletion = true
|
||||
opts.Matcher = source.Fuzzy
|
||||
opts.Literal = true
|
||||
opts.UnimportedCompletion = false
|
||||
})
|
||||
want := expected(t, test, items)
|
||||
|
|
|
|||
|
|
@ -466,7 +466,7 @@ func Completion(ctx context.Context, snapshot Snapshot, fh FileHandle, pos proto
|
|||
documentation: opts.CompletionDocumentation,
|
||||
fullDocumentation: opts.HoverKind == FullDocumentation,
|
||||
placeholders: opts.Placeholders,
|
||||
literal: opts.Literal,
|
||||
literal: opts.InsertTextFormat == protocol.SnippetTextFormat,
|
||||
budget: opts.CompletionBudget,
|
||||
},
|
||||
// default to a matcher that always matches
|
||||
|
|
|
|||
|
|
@ -81,7 +81,6 @@ var (
|
|||
DeepCompletion: true,
|
||||
UnimportedCompletion: true,
|
||||
CompletionDocumentation: true,
|
||||
Literal: true,
|
||||
}
|
||||
DefaultHooks = Hooks{
|
||||
ComputeEdits: myers.ComputeEdits,
|
||||
|
|
@ -159,9 +158,6 @@ type UserOptions struct {
|
|||
// Placeholders adds placeholders to parameters and structs in completion
|
||||
// results.
|
||||
Placeholders bool
|
||||
|
||||
// Literal enables completion for map, slice, and function literals.
|
||||
Literal bool
|
||||
}
|
||||
|
||||
type completionOptions struct {
|
||||
|
|
|
|||
|
|
@ -106,9 +106,14 @@ func (r *runner) Completion(t *testing.T, src span.Span, test tests.Completion,
|
|||
}
|
||||
_, got := r.callCompletion(t, src, func(opts *source.Options) {
|
||||
opts.Matcher = source.CaseInsensitive
|
||||
opts.Literal = strings.Contains(string(src.URI()), "literal")
|
||||
opts.DeepCompletion = false
|
||||
opts.UnimportedCompletion = false
|
||||
opts.InsertTextFormat = protocol.PlainTextTextFormat
|
||||
// Only enable literal completions if in the completion literals tests.
|
||||
// TODO(rstambler): Separate out literal completion tests.
|
||||
if strings.Contains(string(src.URI()), "literal") {
|
||||
opts.InsertTextFormat = protocol.SnippetTextFormat
|
||||
}
|
||||
})
|
||||
if !strings.Contains(string(src.URI()), "builtins") {
|
||||
got = tests.FilterBuiltins(got)
|
||||
|
|
@ -122,7 +127,6 @@ func (r *runner) CompletionSnippet(t *testing.T, src span.Span, expected tests.C
|
|||
_, list := r.callCompletion(t, src, func(opts *source.Options) {
|
||||
opts.Placeholders = placeholders
|
||||
opts.DeepCompletion = true
|
||||
opts.Literal = true
|
||||
})
|
||||
got := tests.FindItem(list, *items[expected.CompletionItem])
|
||||
want := expected.PlainSnippet
|
||||
|
|
@ -217,7 +221,6 @@ func (r *runner) RankCompletion(t *testing.T, src span.Span, test tests.Completi
|
|||
_, got := r.callCompletion(t, src, func(opts *source.Options) {
|
||||
opts.DeepCompletion = true
|
||||
opts.Matcher = source.Fuzzy
|
||||
opts.Literal = true
|
||||
})
|
||||
if msg := tests.CheckCompletionOrder(want, got, true); msg != "" {
|
||||
t.Errorf("%s: %s", src, msg)
|
||||
|
|
|
|||
Loading…
Reference in New Issue