Skip to content

Commit eaf3d32

Browse files
FMorschelCommit Queue
authored andcommitted
[DAS] Fixes dot-shorthands completion for enum constant creation
Fixes: #62168 Change-Id: I435835016e5c213deab3f9979dd554d06cd40fa6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/466140 Reviewed-by: Samuel Rawlins <srawlins@google.com> Reviewed-by: Kallen Tu <kallentu@google.com> Commit-Queue: Kallen Tu <kallentu@google.com> Auto-Submit: Felipe Morschel <git@fmorschel.dev>
1 parent d4df911 commit eaf3d32

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,10 @@ extension on ArgumentList {
14301430
if (parent.element case ConstructorElement constructorElement) {
14311431
return constructorElement.type;
14321432
}
1433+
} else if (parent is EnumConstantArguments) {
1434+
if (parent.parent case EnumConstantDeclaration enumConstantDeclaration) {
1435+
return enumConstantDeclaration.constructorElement?.type;
1436+
}
14331437
}
14341438
return null;
14351439
}

pkg/analysis_server/test/services/completion/dart/declaration/enum_test.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,26 @@ suggestions
301301
''');
302302
}
303303

304+
Future<void> test_dotShorthand_onDeclaration() async {
305+
await computeSuggestions('''
306+
enum E0 {
307+
c0,
308+
c1(.^);
309+
310+
const E0([E0? other]);
311+
}
312+
''');
313+
assertResponse(r'''
314+
suggestions
315+
c0
316+
kind: enumConstant
317+
c1
318+
kind: enumConstant
319+
values
320+
kind: field
321+
''');
322+
}
323+
304324
Future<void> test_enumConstantName() async {
305325
await _check_locations(
306326
declaration: '''

pkg/analysis_server/test/src/services/completion/dart/feature_computer_test.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,17 @@ void f() {
505505
''', 'String');
506506
}
507507

508+
Future<void> test_dotShorthand_enumConstantCreation() async {
509+
await assertContextType('''
510+
enum E0 {
511+
c0,
512+
c1(.^);
513+
514+
const E0([E0? other]);
515+
}
516+
''', 'E0?');
517+
}
518+
508519
Future<void> test_dotShorthand_guardedPattern_switchExpression() async {
509520
await assertContextType('''
510521
enum E { a }

0 commit comments

Comments
 (0)