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 <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
diff --git a/internal/lsp/completion_test.go b/internal/lsp/completion_test.go
index a8955e6..6dca51f 100644
--- a/internal/lsp/completion_test.go
+++ b/internal/lsp/completion_test.go
@@ -15,6 +15,7 @@
 		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)
@@ -31,6 +32,7 @@
 		opts.DeepCompletion = true
 		opts.Matcher = source.Fuzzy
 		opts.Literal = true
+		opts.UnimportedCompletion = false
 	})
 	got := tests.FindItem(list, *items[expected.CompletionItem])
 	want := expected.PlainSnippet
@@ -43,9 +45,7 @@
 }
 
 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)
 	}
@@ -59,6 +59,7 @@
 	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)
@@ -73,6 +74,7 @@
 	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)
@@ -86,6 +88,7 @@
 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)
@@ -101,6 +104,7 @@
 		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 != "" {
diff --git a/internal/lsp/source/options.go b/internal/lsp/source/options.go
index 1584981..1dbc75b 100644
--- a/internal/lsp/source/options.go
+++ b/internal/lsp/source/options.go
@@ -79,6 +79,7 @@
 		LinkTarget:              "pkg.go.dev",
 		Matcher:                 Fuzzy,
 		DeepCompletion:          true,
+		UnimportedCompletion:    true,
 		CompletionDocumentation: true,
 		Literal:                 true,
 	}
diff --git a/internal/lsp/source/source_test.go b/internal/lsp/source/source_test.go
index dcfe7cc..bbab05a 100644
--- a/internal/lsp/source/source_test.go
+++ b/internal/lsp/source/source_test.go
@@ -106,6 +106,7 @@
 		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)
@@ -136,9 +137,7 @@
 	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)
 	}
@@ -155,6 +154,7 @@
 	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)
@@ -180,6 +180,7 @@
 	_, 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)
@@ -196,6 +197,7 @@
 	}
 	_, 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)