Skip to content

Commit

Permalink
internal/lsp/source: enable unimported completions by default
Browse files Browse the repository at this point in the history
Fixes golang/go#31906.

Change-Id: I626ff1fe94a171d2280d9deeb4578b5abc759913
Reviewed-on: https://go-review.googlesource.com/c/tools/+/214947
Run-TryBot: Heschi Kreinick <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Rebecca Stambler <[email protected]>
  • Loading branch information
heschi committed Jan 17, 2020
1 parent fe56e63 commit 0cba7a3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
10 changes: 7 additions & 3 deletions internal/lsp/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func (r *runner) Completion(t *testing.T, src span.Span, test tests.Completion,
opts.DeepCompletion = false
opts.Matcher = source.CaseInsensitive
opts.Literal = strings.Contains(string(src.URI()), "literal")
opts.UnimportedCompletion = false
})
if !strings.Contains(string(src.URI()), "builtins") {
got = tests.FilterBuiltins(got)
Expand All @@ -31,6 +32,7 @@ func (r *runner) CompletionSnippet(t *testing.T, src span.Span, expected tests.C
opts.DeepCompletion = true
opts.Matcher = source.Fuzzy
opts.Literal = true
opts.UnimportedCompletion = false
})
got := tests.FindItem(list, *items[expected.CompletionItem])
want := expected.PlainSnippet
Expand All @@ -43,9 +45,7 @@ func (r *runner) CompletionSnippet(t *testing.T, src span.Span, expected tests.C
}

func (r *runner) UnimportedCompletion(t *testing.T, src span.Span, test tests.Completion, items tests.CompletionItems) {
got := r.callCompletion(t, src, func(opts *source.Options) {
opts.UnimportedCompletion = true
})
got := r.callCompletion(t, src, func(opts *source.Options) {})
if !strings.Contains(string(src.URI()), "builtins") {
got = tests.FilterBuiltins(got)
}
Expand All @@ -59,6 +59,7 @@ func (r *runner) DeepCompletion(t *testing.T, src span.Span, test tests.Completi
got := r.callCompletion(t, src, func(opts *source.Options) {
opts.DeepCompletion = true
opts.Matcher = source.CaseInsensitive
opts.UnimportedCompletion = false
})
if !strings.Contains(string(src.URI()), "builtins") {
got = tests.FilterBuiltins(got)
Expand All @@ -73,6 +74,7 @@ func (r *runner) FuzzyCompletion(t *testing.T, src span.Span, test tests.Complet
got := r.callCompletion(t, src, func(opts *source.Options) {
opts.DeepCompletion = true
opts.Matcher = source.Fuzzy
opts.UnimportedCompletion = false
})
if !strings.Contains(string(src.URI()), "builtins") {
got = tests.FilterBuiltins(got)
Expand All @@ -86,6 +88,7 @@ func (r *runner) FuzzyCompletion(t *testing.T, src span.Span, test tests.Complet
func (r *runner) CaseSensitiveCompletion(t *testing.T, src span.Span, test tests.Completion, items tests.CompletionItems) {
got := r.callCompletion(t, src, func(opts *source.Options) {
opts.Matcher = source.CaseSensitive
opts.UnimportedCompletion = false
})
if !strings.Contains(string(src.URI()), "builtins") {
got = tests.FilterBuiltins(got)
Expand All @@ -101,6 +104,7 @@ func (r *runner) RankCompletion(t *testing.T, src span.Span, test tests.Completi
opts.DeepCompletion = true
opts.Matcher = source.Fuzzy
opts.Literal = true
opts.UnimportedCompletion = false
})
want := expected(t, test, items)
if msg := tests.CheckCompletionOrder(want, got, true); msg != "" {
Expand Down
1 change: 1 addition & 0 deletions internal/lsp/source/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ var (
LinkTarget: "pkg.go.dev",
Matcher: Fuzzy,
DeepCompletion: true,
UnimportedCompletion: true,
CompletionDocumentation: true,
Literal: true,
}
Expand Down
8 changes: 5 additions & 3 deletions internal/lsp/source/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func (r *runner) Completion(t *testing.T, src span.Span, test tests.Completion,
opts.Matcher = source.CaseInsensitive
opts.Literal = strings.Contains(string(src.URI()), "literal")
opts.DeepCompletion = false
opts.UnimportedCompletion = false
})
if !strings.Contains(string(src.URI()), "builtins") {
got = tests.FilterBuiltins(got)
Expand Down Expand Up @@ -136,9 +137,7 @@ func (r *runner) UnimportedCompletion(t *testing.T, src span.Span, test tests.Co
for _, pos := range test.CompletionItems {
want = append(want, tests.ToProtocolCompletionItem(*items[pos]))
}
_, got := r.callCompletion(t, src, func(opts *source.Options) {
opts.UnimportedCompletion = true
})
_, got := r.callCompletion(t, src, func(opts *source.Options) {})
if !strings.Contains(string(src.URI()), "builtins") {
got = tests.FilterBuiltins(got)
}
Expand All @@ -155,6 +154,7 @@ func (r *runner) DeepCompletion(t *testing.T, src span.Span, test tests.Completi
prefix, list := r.callCompletion(t, src, func(opts *source.Options) {
opts.DeepCompletion = true
opts.Matcher = source.CaseInsensitive
opts.UnimportedCompletion = false
})
if !strings.Contains(string(src.URI()), "builtins") {
list = tests.FilterBuiltins(list)
Expand All @@ -180,6 +180,7 @@ func (r *runner) FuzzyCompletion(t *testing.T, src span.Span, test tests.Complet
_, got := r.callCompletion(t, src, func(opts *source.Options) {
opts.DeepCompletion = true
opts.Matcher = source.Fuzzy
opts.UnimportedCompletion = false
})
if !strings.Contains(string(src.URI()), "builtins") {
got = tests.FilterBuiltins(got)
Expand All @@ -196,6 +197,7 @@ func (r *runner) CaseSensitiveCompletion(t *testing.T, src span.Span, test tests
}
_, list := r.callCompletion(t, src, func(opts *source.Options) {
opts.Matcher = source.CaseSensitive
opts.UnimportedCompletion = false
})
if !strings.Contains(string(src.URI()), "builtins") {
list = tests.FilterBuiltins(list)
Expand Down

0 comments on commit 0cba7a3

Please sign in to comment.