Skip to content

Commit ea09fbe

Browse files
pqcommit-bot@chromium.org
authored andcommitted
switch case statement completions
follow-up from: https://dart-review.googlesource.com/c/sdk/+/114748 Change-Id: If92ac6e67298e8950d7da57c0d1892cb29ae8c7b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/114756 Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Dan Rubel <[email protected]> Commit-Queue: Phil Quitslund <[email protected]>
1 parent 05c28c6 commit ea09fbe

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ class _KeywordVisitor extends GeneralizingAstVisitor {
648648

649649
@override
650650
visitSwitchCase(SwitchCase node) {
651-
_addSuggestion(Keyword.BREAK);
651+
_addStatementKeywords(node);
652652
return super.visitSwitchCase(node);
653653
}
654654

pkg/analysis_server/test/services/completion/dart/keyword_contributor_test.dart

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,44 @@ class KeywordContributorTest extends DartCompletionContributorTest {
174174
Keyword.WHILE
175175
];
176176

177+
List<Keyword> get statementStartInSwitchCaseInClass => [
178+
Keyword.ASSERT,
179+
Keyword.BREAK,
180+
Keyword.CONST,
181+
Keyword.DO,
182+
Keyword.FINAL,
183+
Keyword.FOR,
184+
Keyword.IF,
185+
Keyword.NEW,
186+
Keyword.RETURN,
187+
Keyword.SUPER,
188+
Keyword.THIS,
189+
Keyword.SWITCH,
190+
Keyword.THROW,
191+
Keyword.TRY,
192+
Keyword.VAR,
193+
Keyword.VOID,
194+
Keyword.WHILE
195+
];
196+
197+
List<Keyword> get statementStartInSwitchCaseOutsideClass => [
198+
Keyword.ASSERT,
199+
Keyword.BREAK,
200+
Keyword.CONST,
201+
Keyword.DO,
202+
Keyword.FINAL,
203+
Keyword.FOR,
204+
Keyword.IF,
205+
Keyword.NEW,
206+
Keyword.RETURN,
207+
Keyword.SWITCH,
208+
Keyword.THROW,
209+
Keyword.TRY,
210+
Keyword.VAR,
211+
Keyword.VOID,
212+
Keyword.WHILE
213+
];
214+
177215
List<Keyword> get statementStartInSwitchInClass => [
178216
Keyword.ASSERT,
179217
Keyword.BREAK,
@@ -1986,13 +2024,13 @@ f() => [...^];
19862024
test_switch_statement_case_break_insideClass() async {
19872025
addTestSource('class A{foo() {switch(1) {case 1: b^}}}');
19882026
await computeSuggestions();
1989-
assertSuggestKeywords([Keyword.BREAK]);
2027+
assertSuggestKeywords(statementStartInSwitchCaseInClass);
19902028
}
19912029

19922030
test_switch_statement_case_break_outsideClass() async {
19932031
addTestSource('foo() {switch(1) {case 1: b^}}');
19942032
await computeSuggestions();
1995-
assertSuggestKeywords([Keyword.BREAK]);
2033+
assertSuggestKeywords(statementStartInSwitchCaseOutsideClass);
19962034
}
19972035

19982036
test_switch_statement_insideClass() async {
@@ -2169,6 +2207,14 @@ class KeywordContributorWithNnbdTest extends KeywordContributorTest {
21692207
List<Keyword> get statementStartInLoopOutsideClass =>
21702208
super.statementStartInLoopOutsideClass..add(Keyword.LATE);
21712209

2210+
@override
2211+
List<Keyword> get statementStartInSwitchCaseInClass =>
2212+
super.statementStartInSwitchCaseInClass..add(Keyword.LATE);
2213+
2214+
@override
2215+
List<Keyword> get statementStartInSwitchCaseOutsideClass =>
2216+
super.statementStartInSwitchCaseOutsideClass..add(Keyword.LATE);
2217+
21722218
@override
21732219
List<Keyword> get statementStartInSwitchInClass =>
21742220
super.statementStartInSwitchInClass..add(Keyword.LATE);

0 commit comments

Comments
 (0)