Revert "Stop using available suggestions for already imported libraries"

This reverts commit 3cc518b3cce843be20a76111151a63c8d224b05e.
Initial CL: https://dart-review.googlesource.com/c/sdk/+/201021

Bug: https://github.com/flutter/flutter-intellij/issues/5761
Change-Id: I62e57deef819f78f1d08934ad924585eaa52223b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/214225
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Jacob Richman <jacobr@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analysis_server/lib/src/cider/completion.dart b/pkg/analysis_server/lib/src/cider/completion.dart
index 458ce08..8591b99 100644
--- a/pkg/analysis_server/lib/src/cider/completion.dart
+++ b/pkg/analysis_server/lib/src/cider/completion.dart
@@ -99,7 +99,6 @@
             return await manager.computeSuggestions(
               performance,
               completionRequest,
-              enableImportedReferenceContributor: false,
               enableOverrideContributor: false,
               enableUriContributor: false,
             );
diff --git a/pkg/analysis_server/lib/src/domains/completion/available_suggestions.dart b/pkg/analysis_server/lib/src/domains/completion/available_suggestions.dart
index e433551..1d4b4b5 100644
--- a/pkg/analysis_server/lib/src/domains/completion/available_suggestions.dart
+++ b/pkg/analysis_server/lib/src/domains/completion/available_suggestions.dart
@@ -37,9 +37,8 @@
   ) {
     int relevance;
     if (importedUriSet.contains(library.uri)) {
-      return;
-    }
-    if (library.isDeprecated) {
+      relevance = importedRelevance;
+    } else if (library.isDeprecated) {
       relevance = deprecatedRelevance;
     } else {
       relevance = otherwiseRelevance;
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/completion_manager.dart b/pkg/analysis_server/lib/src/services/completion/dart/completion_manager.dart
index 61eea1c..cec2be3 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/completion_manager.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/completion_manager.dart
@@ -92,7 +92,6 @@
   Future<List<CompletionSuggestion>> computeSuggestions(
     OperationPerformanceImpl performance,
     CompletionRequest request, {
-    bool enableImportedReferenceContributor = true,
     bool enableOverrideContributor = true,
     bool enableUriContributor = true,
     CompletionPreference? completionPreference,
@@ -131,7 +130,6 @@
       CombinatorContributor(),
       ExtensionMemberContributor(),
       FieldFormalContributor(),
-      if (enableImportedReferenceContributor) ImportedReferenceContributor(),
       KeywordContributor(),
       LabelContributor(),
       LibraryMemberContributor(),
@@ -150,6 +148,8 @@
     if (includedElementKinds != null) {
       _addIncludedElementKinds(dartRequest);
       _addIncludedSuggestionRelevanceTags(dartRequest);
+    } else {
+      contributors.add(ImportedReferenceContributor());
     }
 
     try {
diff --git a/pkg/analysis_server/test/client/completion_driver_test.dart b/pkg/analysis_server/test/client/completion_driver_test.dart
index d122baf..3f888c5 100644
--- a/pkg/analysis_server/test/client/completion_driver_test.dart
+++ b/pkg/analysis_server/test/client/completion_driver_test.dart
@@ -71,7 +71,6 @@
   }
 
   void assertSuggestion({
-    bool allowMultiple = false,
     required String completion,
     ElementKind? element,
     CompletionSuggestionKind? kind,
@@ -79,7 +78,6 @@
   }) {
     expect(
         suggestionWith(
-          allowMultiple: allowMultiple,
           completion: completion,
           element: element,
           kind: kind,
@@ -184,7 +182,6 @@
           completion: completion, element: element, kind: kind, file: file));
 
   CompletionSuggestion suggestionWith({
-    bool allowMultiple = false,
     required String completion,
     ElementKind? element,
     CompletionSuggestionKind? kind,
@@ -192,9 +189,7 @@
   }) {
     final matches = suggestionsWith(
         completion: completion, element: element, kind: kind, file: file);
-    if (!allowMultiple) {
-      expect(matches, hasLength(1));
-    }
+    expect(matches, hasLength(1));
     return matches.first;
   }
 
@@ -269,10 +264,7 @@
 }
 ''');
 
-    // TODO(brianwilkerson) There should be a single suggestion here after we
-    //  figure out how to stop the duplication.
     assertSuggestion(
-        allowMultiple: true,
         completion: 'A',
         element: ElementKind.CONSTRUCTOR,
         kind: CompletionSuggestionKind.INVOCATION);
@@ -296,11 +288,7 @@
   ^
 }
 ''');
-
-    // TODO(brianwilkerson) There should be a single suggestion here after we
-    //  figure out how to stop the duplication.
     assertSuggestion(
-        allowMultiple: true,
         completion: 'E.e',
         element: ElementKind.ENUM_CONSTANT,
         kind: CompletionSuggestionKind.INVOCATION);
@@ -325,10 +313,7 @@
 }
 ''');
 
-    // TODO(brianwilkerson) There should be a single suggestion here after we
-    //  figure out how to stop the duplication.
     assertSuggestion(
-        allowMultiple: true,
         completion: 'A.a',
         element: ElementKind.CONSTRUCTOR,
         kind: CompletionSuggestionKind.INVOCATION);
@@ -661,15 +646,13 @@
 }
 ''');
 
-    // TODO(brianwilkerson) There should be a single suggestion here after we
-    //  figure out how to stop the duplication.
     expect(
         suggestionsWith(
             completion: 'Future.value',
             file: '/sdk/lib/async/async.dart',
             element: ElementKind.CONSTRUCTOR,
             kind: CompletionSuggestionKind.INVOCATION),
-        hasLength(2));
+        hasLength(1));
   }
 
   Future<void> test_sdk_lib_suggestions() async {
diff --git a/pkg/analysis_server/test/lsp/completion_dart_test.dart b/pkg/analysis_server/test/lsp/completion_dart_test.dart
index 0328fa0..9ccf020 100644
--- a/pkg/analysis_server/test/lsp/completion_dart_test.dart
+++ b/pkg/analysis_server/test/lsp/completion_dart_test.dart
@@ -1560,7 +1560,7 @@
     expect(completions, hasLength(1));
     final resolved = await resolveCompletion(completions.first);
     // It should not include auto-import text since it's already imported.
-    expect(resolved.detail, isNot(contains('Auto import from')));
+    expect(resolved.detail, isNull);
   }
 
   Future<void> test_suggestionSets_filtersOutAlreadyImportedSymbols() async {
diff --git a/pkg/analysis_server/test/services/completion/dart/relevance/bool_assignment_test.dart b/pkg/analysis_server/test/services/completion/dart/relevance/bool_assignment_test.dart
index b796a44..039c915 100644
--- a/pkg/analysis_server/test/services/completion/dart/relevance/bool_assignment_test.dart
+++ b/pkg/analysis_server/test/services/completion/dart/relevance/bool_assignment_test.dart
@@ -15,13 +15,7 @@
 
 @reflectiveTest
 class BoolAssignmentTest extends CompletionRelevanceTest {
-  @failingTest
   Future<void> test_boolLiterals_imported() async {
-    // TODO(brianwilkerson) This test is arguably invalid given that there's no
-    //  data to suggest that the boolean keywords should appear before a
-    //  constructor in the list, but it does seem likely to be valid in this
-    //  case, so we should investigate features that might cause this test to
-    //  start passing again.
     await addTestFile('''
 foo() {
   bool b;