[Completion]Do not suggest constructors if element is not visible.

Change-Id: Ic5ebec233199a6d9cf0faf370ac3114bc0251b32
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/438580
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/declaration_helper.dart b/pkg/analysis_server/lib/src/services/completion/dart/declaration_helper.dart
index b28e8c9..e9ec9b5 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/declaration_helper.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/declaration_helper.dart
@@ -1831,6 +1831,18 @@
     if (mustBeAssignable) {
       return;
     }
+    if (checkVisibilty &&
+        !visibilityTracker.isVisible(
+          element: constructors.first.enclosingElement,
+          importData: importData,
+        )) {
+      return;
+    }
+
+    if (checkVisibilty) {
+      checkVisibilty = false;
+    }
+
     for (var constructor in constructors) {
       if (constructor.isVisibleIn(request.libraryElement) &&
           (allowNonFactory || constructor.isFactory)) {
diff --git a/pkg/analysis_server/test/services/completion/dart/completion_test.dart b/pkg/analysis_server/test/services/completion/dart/completion_test.dart
index cc27ccb..837974e 100644
--- a/pkg/analysis_server/test/services/completion/dart/completion_test.dart
+++ b/pkg/analysis_server/test/services/completion/dart/completion_test.dart
@@ -4881,18 +4881,6 @@
 suggestions
   Map
     kind: constructorInvocation
-  Map.from
-    kind: constructorInvocation
-  Map.fromEntries
-    kind: constructorInvocation
-  Map.fromIterable
-    kind: constructorInvocation
-  Map.fromIterables
-    kind: constructorInvocation
-  Map.identity
-    kind: constructorInvocation
-  Map.unmodifiable
-    kind: constructorInvocation
 ''');
   }
 
@@ -4905,18 +4893,6 @@
 suggestions
   Map
     kind: constructorInvocation
-  Map.from
-    kind: constructorInvocation
-  Map.fromEntries
-    kind: constructorInvocation
-  Map.fromIterable
-    kind: constructorInvocation
-  Map.fromIterables
-    kind: constructorInvocation
-  Map.identity
-    kind: constructorInvocation
-  Map.unmodifiable
-    kind: constructorInvocation
 ''');
   }
 
@@ -4929,18 +4905,6 @@
 suggestions
   Map
     kind: constructorInvocation
-  Map.from
-    kind: constructorInvocation
-  Map.fromEntries
-    kind: constructorInvocation
-  Map.fromIterable
-    kind: constructorInvocation
-  Map.fromIterables
-    kind: constructorInvocation
-  Map.identity
-    kind: constructorInvocation
-  Map.unmodifiable
-    kind: constructorInvocation
 ''');
   }
 
@@ -5372,10 +5336,6 @@
 suggestions
   List
     kind: constructorInvocation
-  List.empty
-    kind: constructorInvocation
-  List.generate
-    kind: constructorInvocation
 ''');
   }
 
@@ -5522,18 +5482,6 @@
 suggestions
   List
     kind: constructorInvocation
-  List.empty
-    kind: constructorInvocation
-  List.filled
-    kind: constructorInvocation
-  List.from
-    kind: constructorInvocation
-  List.generate
-    kind: constructorInvocation
-  List.of
-    kind: constructorInvocation
-  List.unmodifiable
-    kind: constructorInvocation
   XXX.fisk
     kind: constructorInvocation
 ''');