Stop suggesting methods in object patterns

Fixes: 52058
Change-Id: I031fcd2b48975729cca48f640c3d86f5d2cfc0b0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/296420
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/suggestion_builder.dart b/pkg/analysis_server/lib/src/services/completion/dart/suggestion_builder.dart
index 4fe3a28..a3d6506 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/suggestion_builder.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/suggestion_builder.dart
@@ -105,7 +105,8 @@
       required CompletionSuggestionKind kind,
       required double inheritanceDistance}) {
     if (method.isAccessibleIn(request.libraryElement) &&
-        _shouldAddSuggestion(method)) {
+        _shouldAddSuggestion(method) &&
+        request.opType.patternLocation == null) {
       builder.suggestMethod(method,
           kind: kind, inheritanceDistance: inheritanceDistance);
     }
diff --git a/pkg/analysis_server/test/services/completion/dart/location/object_pattern_test.dart b/pkg/analysis_server/test/services/completion/dart/location/object_pattern_test.dart
index 6a4472d..9c1abcf 100644
--- a/pkg/analysis_server/test/services/completion/dart/location/object_pattern_test.dart
+++ b/pkg/analysis_server/test/services/completion/dart/location/object_pattern_test.dart
@@ -32,7 +32,7 @@
       test_declarationContext_pattern_first_withoutGetter_afterColon() async {
     await computeSuggestions('''
 void f1(A1 x0) {
-  var A1(: ^) = x0; 
+  var A1(: ^) = x0;
 }
 class A0 {
   int f01 = 0;
@@ -65,10 +65,6 @@
     kind: getter
   g11
     kind: getter
-  m01
-    kind: methodInvocation
-  m11
-    kind: methodInvocation
 ''');
   }
 
@@ -76,7 +72,7 @@
       test_declarationContext_pattern_first_withoutGetter_afterColon_partial() async {
     await computeSuggestions('''
 void f1(A1 x0) {
-  var A1(: g^) = x0; 
+  var A1(: g^) = x0;
 }
 class A0 {
   int f01 = 0;
@@ -122,10 +118,6 @@
     kind: getter
   g11
     kind: getter
-  m01
-    kind: methodInvocation
-  m11
-    kind: methodInvocation
 ''');
     }
   }
@@ -191,10 +183,6 @@
     kind: getter
   g11
     kind: getter
-  m01
-    kind: methodInvocation
-  m11
-    kind: methodInvocation
 ''');
   }
 
@@ -402,10 +390,6 @@
     kind: getter
   g11
     kind: getter
-  m01
-    kind: methodInvocation
-  m11
-    kind: methodInvocation
 ''');
   }
 
@@ -460,10 +444,6 @@
     kind: getter
   g11
     kind: getter
-  m01
-    kind: methodInvocation
-  m11
-    kind: methodInvocation
 ''');
     }
   }
@@ -520,10 +500,6 @@
     kind: getter
   g11
     kind: getter
-  m01
-    kind: methodInvocation
-  m11
-    kind: methodInvocation
 ''');
     }
   }
@@ -569,10 +545,6 @@
     kind: getter
   g11
     kind: getter
-  m01
-    kind: methodInvocation
-  m11
-    kind: methodInvocation
 ''');
   }
 
@@ -612,10 +584,6 @@
     kind: getter
   g11
     kind: getter
-  m01
-    kind: methodInvocation
-  m11
-    kind: methodInvocation
 ''');
   }
 }
diff --git a/pkg/analyzer_plugin/lib/src/utilities/completion/optype.dart b/pkg/analyzer_plugin/lib/src/utilities/completion/optype.dart
index b731196..98055b9 100644
--- a/pkg/analyzer_plugin/lib/src/utilities/completion/optype.dart
+++ b/pkg/analyzer_plugin/lib/src/utilities/completion/optype.dart
@@ -1164,6 +1164,13 @@
 
   @override
   void visitObjectPattern(ObjectPattern node) {
+    if (node.leftParenthesis.end <= offset &&
+        offset <= node.rightParenthesis.offset) {
+      optype.patternLocation = NamedPatternFieldWantsName(
+        matchedType: node.type.typeOrThrow,
+        existingFields: node.fields,
+      );
+    }
     optype.completionLocation = 'ObjectPattern_fieldName';
   }