Skip to content

Commit f18bd99

Browse files
FMorschelCommit Queue
authored andcommitted
[DAS] Fixes comment references for enum constants
Fixes: #60760 Change-Id: I1a6dc74f1265ac4195f772a3e0374856008cbc6f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/430000 Commit-Queue: Brian Wilkerson <[email protected]> Auto-Submit: Felipe Morschel <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]>
1 parent c98a91f commit f18bd99

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

pkg/analysis_server/lib/src/services/completion/dart/declaration_helper.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,10 @@ class DeclarationHelper {
399399
return;
400400
}
401401
AstNode? parent = containingMember.parent ?? containingMember;
402-
if (parent is ClassMember) {
402+
if (parent is EnumConstantDeclaration) {
403+
assert(node is CommentReference);
404+
parent = parent.parent;
405+
} else if (parent is ClassMember) {
403406
assert(node is CommentReference);
404407
parent = parent.parent;
405408
} else if (parent is Directive) {

pkg/analysis_server/test/services/completion/dart/location/dart_doc_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,23 @@ suggestions
7676
''');
7777
}
7878

79+
Future<void> test_enumConstant() async {
80+
allowedIdentifiers = const {'value1'};
81+
await computeSuggestions('''
82+
enum MyEnum {
83+
/// This doc should suggest the commented enum constant name [val^].
84+
value1
85+
}
86+
''');
87+
assertResponse(r'''
88+
replacement
89+
left: 3
90+
suggestions
91+
value1
92+
kind: enumConstant
93+
''');
94+
}
95+
7996
Future<void> test_extension() async {
8097
allowedIdentifiers = const {'MyExt'};
8198
await computeSuggestions('''

pkg/analyzer/lib/src/dart/ast/to_source_visitor.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,10 @@ class ToSourceVisitor implements AstVisitor<void> {
227227
void visitComment(Comment node) {}
228228

229229
@override
230-
void visitCommentReference(CommentReference node) {}
230+
void visitCommentReference(CommentReference node) {
231+
sink.write(node.newKeyword?.lexeme ?? '');
232+
_visitNode(prefix: '[', node.expression, suffix: ']');
233+
}
231234

232235
@override
233236
void visitCompilationUnit(CompilationUnit node) {

pkg/analyzer/test/src/dart/ast/to_source_visitor_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ void f() {}
634634
/// [$code]
635635
void f() {}
636636
''');
637-
_assertSource('', findNode.commentReference(code));
637+
_assertSource('[x]', findNode.commentReference(code));
638638
}
639639

640640
void test_visitCompilationUnit_declaration() {

0 commit comments

Comments
 (0)