[analysis_server] Prevent extension methods showing in completion in comments

Fixes https://github.com/dart-lang/sdk/issues/46351.

Change-Id: I762ccccceb0ec0fa453f5acb727e8c94472ac45d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/203501
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/extension_member_contributor.dart b/pkg/analysis_server/lib/src/services/completion/dart/extension_member_contributor.dart
index 036786e..cfbdb7f 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/extension_member_contributor.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/extension_member_contributor.dart
@@ -31,6 +31,10 @@
     var expression = request.dotTarget;
 
     if (expression == null) {
+      if (!request.includeIdentifiers) {
+        return;
+      }
+
       var classOrMixin = request.target.containingNode
           .thisOrAncestorOfType<ClassOrMixinDeclaration>();
       if (classOrMixin != null) {
diff --git a/pkg/analysis_server/test/domain_completion_test.dart b/pkg/analysis_server/test/domain_completion_test.dart
index 08d3056..fd933fa 100644
--- a/pkg/analysis_server/test/domain_completion_test.dart
+++ b/pkg/analysis_server/test/domain_completion_test.dart
@@ -538,6 +538,23 @@
     expect(suggestions, isEmpty);
   }
 
+  Future<void> test_inDartDoc3() async {
+    addTestFile('''
+class MyClass {
+  /// ^
+  void foo() {}
+
+  void bar() {}
+}
+
+extension MyClassExtension on MyClass {
+  void baz() {}
+}
+  ''');
+    await getSuggestions();
+    expect(suggestions, isEmpty);
+  }
+
   Future<void> test_inDartDoc_reference1() async {
     newFile('/testA.dart', content: '''
   part of libA;
@@ -564,6 +581,24 @@
     assertHasResult(CompletionSuggestionKind.IDENTIFIER, 'main');
   }
 
+  Future<void> test_inDartDoc_reference3() async {
+    addTestFile('''
+class MyClass {
+  /// [^]
+  void foo() {}
+
+  void bar() {}
+}
+
+extension MyClassExtension on MyClass {
+  void baz() {}
+}
+  ''');
+    await getSuggestions();
+    assertHasResult(CompletionSuggestionKind.IDENTIFIER, 'bar');
+    assertHasResult(CompletionSuggestionKind.INVOCATION, 'baz');
+  }
+
   Future<void> test_inherited() {
     addTestFile('''
 class A {