[analysis_server] Suppress code completion in comments before dartdocs
Fixes https://github.com/Dart-Code/Dart-Code/issues/3783.
Change-Id: I8539d8b525534ad85b42618a6a3e9888fb43c851
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/228540
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analysis_server/test/domain_completion_test.dart b/pkg/analysis_server/test/domain_completion_test.dart
index 2c3a578..ab3ae47 100644
--- a/pkg/analysis_server/test/domain_completion_test.dart
+++ b/pkg/analysis_server/test/domain_completion_test.dart
@@ -2034,6 +2034,17 @@
});
}
+ Future<void> test_inComment_block_beforeDartDoc() async {
+ addTestFile('''
+/* text ^ */
+
+/// some doc comments
+class SomeClass {}
+ ''');
+ await getSuggestions();
+ expect(suggestions, isEmpty);
+ }
+
Future<void> test_inComment_block_beforeNode() async {
addTestFile('''
void f(aaa, bbb) {
@@ -2059,6 +2070,17 @@
expect(suggestions, isEmpty);
}
+ Future<void> test_inComment_endOfLine_beforeDartDoc() async {
+ addTestFile('''
+// text ^
+
+/// some doc comments
+class SomeClass {}
+ ''');
+ await getSuggestions();
+ expect(suggestions, isEmpty);
+ }
+
Future<void> test_inComment_endOfLine_beforeNode() async {
addTestFile('''
void f(aaa, bbb) {
diff --git a/pkg/analyzer_plugin/lib/src/utilities/completion/completion_target.dart b/pkg/analyzer_plugin/lib/src/utilities/completion/completion_target.dart
index e235487..9c20706 100644
--- a/pkg/analyzer_plugin/lib/src/utilities/completion/completion_target.dart
+++ b/pkg/analyzer_plugin/lib/src/utilities/completion/completion_target.dart
@@ -564,6 +564,7 @@
if (token.type != TokenType.EOF && offset >= token.offset) {
return null;
}
+ final startToken = token;
token = token.precedingComments;
while (token != null) {
if (offset <= token.offset) {
@@ -576,6 +577,21 @@
}
token = token.next;
}
+
+ // It's possible the supplied token was a DartDoc token and there were
+ // normal comments before it that don't show up in precedingComments so
+ // check for them too.
+ token = startToken.previous;
+ while (token != null &&
+ offset <= token.end &&
+ (token.type == TokenType.SINGLE_LINE_COMMENT ||
+ token.type == TokenType.MULTI_LINE_COMMENT)) {
+ if (offset >= token.offset) {
+ return token;
+ }
+ token = token.previous;
+ }
+
return null;
}