Skip to content

Commit 0cba7a3

Browse files
committed
internal/lsp/source: enable unimported completions by default
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]>
1 parent fe56e63 commit 0cba7a3

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

internal/lsp/completion_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func (r *runner) Completion(t *testing.T, src span.Span, test tests.Completion,
1515
opts.DeepCompletion = false
1616
opts.Matcher = source.CaseInsensitive
1717
opts.Literal = strings.Contains(string(src.URI()), "literal")
18+
opts.UnimportedCompletion = false
1819
})
1920
if !strings.Contains(string(src.URI()), "builtins") {
2021
got = tests.FilterBuiltins(got)
@@ -31,6 +32,7 @@ func (r *runner) CompletionSnippet(t *testing.T, src span.Span, expected tests.C
3132
opts.DeepCompletion = true
3233
opts.Matcher = source.Fuzzy
3334
opts.Literal = true
35+
opts.UnimportedCompletion = false
3436
})
3537
got := tests.FindItem(list, *items[expected.CompletionItem])
3638
want := expected.PlainSnippet
@@ -43,9 +45,7 @@ func (r *runner) CompletionSnippet(t *testing.T, src span.Span, expected tests.C
4345
}
4446

4547
func (r *runner) UnimportedCompletion(t *testing.T, src span.Span, test tests.Completion, items tests.CompletionItems) {
46-
got := r.callCompletion(t, src, func(opts *source.Options) {
47-
opts.UnimportedCompletion = true
48-
})
48+
got := r.callCompletion(t, src, func(opts *source.Options) {})
4949
if !strings.Contains(string(src.URI()), "builtins") {
5050
got = tests.FilterBuiltins(got)
5151
}
@@ -59,6 +59,7 @@ func (r *runner) DeepCompletion(t *testing.T, src span.Span, test tests.Completi
5959
got := r.callCompletion(t, src, func(opts *source.Options) {
6060
opts.DeepCompletion = true
6161
opts.Matcher = source.CaseInsensitive
62+
opts.UnimportedCompletion = false
6263
})
6364
if !strings.Contains(string(src.URI()), "builtins") {
6465
got = tests.FilterBuiltins(got)
@@ -73,6 +74,7 @@ func (r *runner) FuzzyCompletion(t *testing.T, src span.Span, test tests.Complet
7374
got := r.callCompletion(t, src, func(opts *source.Options) {
7475
opts.DeepCompletion = true
7576
opts.Matcher = source.Fuzzy
77+
opts.UnimportedCompletion = false
7678
})
7779
if !strings.Contains(string(src.URI()), "builtins") {
7880
got = tests.FilterBuiltins(got)
@@ -86,6 +88,7 @@ func (r *runner) FuzzyCompletion(t *testing.T, src span.Span, test tests.Complet
8688
func (r *runner) CaseSensitiveCompletion(t *testing.T, src span.Span, test tests.Completion, items tests.CompletionItems) {
8789
got := r.callCompletion(t, src, func(opts *source.Options) {
8890
opts.Matcher = source.CaseSensitive
91+
opts.UnimportedCompletion = false
8992
})
9093
if !strings.Contains(string(src.URI()), "builtins") {
9194
got = tests.FilterBuiltins(got)
@@ -101,6 +104,7 @@ func (r *runner) RankCompletion(t *testing.T, src span.Span, test tests.Completi
101104
opts.DeepCompletion = true
102105
opts.Matcher = source.Fuzzy
103106
opts.Literal = true
107+
opts.UnimportedCompletion = false
104108
})
105109
want := expected(t, test, items)
106110
if msg := tests.CheckCompletionOrder(want, got, true); msg != "" {

internal/lsp/source/options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ var (
7979
LinkTarget: "pkg.go.dev",
8080
Matcher: Fuzzy,
8181
DeepCompletion: true,
82+
UnimportedCompletion: true,
8283
CompletionDocumentation: true,
8384
Literal: true,
8485
}

internal/lsp/source/source_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ func (r *runner) Completion(t *testing.T, src span.Span, test tests.Completion,
106106
opts.Matcher = source.CaseInsensitive
107107
opts.Literal = strings.Contains(string(src.URI()), "literal")
108108
opts.DeepCompletion = false
109+
opts.UnimportedCompletion = false
109110
})
110111
if !strings.Contains(string(src.URI()), "builtins") {
111112
got = tests.FilterBuiltins(got)
@@ -136,9 +137,7 @@ func (r *runner) UnimportedCompletion(t *testing.T, src span.Span, test tests.Co
136137
for _, pos := range test.CompletionItems {
137138
want = append(want, tests.ToProtocolCompletionItem(*items[pos]))
138139
}
139-
_, got := r.callCompletion(t, src, func(opts *source.Options) {
140-
opts.UnimportedCompletion = true
141-
})
140+
_, got := r.callCompletion(t, src, func(opts *source.Options) {})
142141
if !strings.Contains(string(src.URI()), "builtins") {
143142
got = tests.FilterBuiltins(got)
144143
}
@@ -155,6 +154,7 @@ func (r *runner) DeepCompletion(t *testing.T, src span.Span, test tests.Completi
155154
prefix, list := r.callCompletion(t, src, func(opts *source.Options) {
156155
opts.DeepCompletion = true
157156
opts.Matcher = source.CaseInsensitive
157+
opts.UnimportedCompletion = false
158158
})
159159
if !strings.Contains(string(src.URI()), "builtins") {
160160
list = tests.FilterBuiltins(list)
@@ -180,6 +180,7 @@ func (r *runner) FuzzyCompletion(t *testing.T, src span.Span, test tests.Complet
180180
_, got := r.callCompletion(t, src, func(opts *source.Options) {
181181
opts.DeepCompletion = true
182182
opts.Matcher = source.Fuzzy
183+
opts.UnimportedCompletion = false
183184
})
184185
if !strings.Contains(string(src.URI()), "builtins") {
185186
got = tests.FilterBuiltins(got)
@@ -196,6 +197,7 @@ func (r *runner) CaseSensitiveCompletion(t *testing.T, src span.Span, test tests
196197
}
197198
_, list := r.callCompletion(t, src, func(opts *source.Options) {
198199
opts.Matcher = source.CaseSensitive
200+
opts.UnimportedCompletion = false
199201
})
200202
if !strings.Contains(string(src.URI()), "builtins") {
201203
list = tests.FilterBuiltins(list)

0 commit comments

Comments
 (0)