Skip to content

Commit ff5706e

Browse files
DanTupCommit Queue
authored andcommitted
[analysis_server] Exclude the enum body semicolon from format-on-type
`EnumBody.semicolon` is the semicolon between the constants and other members. Since the formatter removes this semicolon if there's nothing after it, we can't have it trigger formatting or it will just immediately delete the semicolon you typed. Fixes #61909 Fixes dart-lang/dart_style#1782 Fixes Dart-Code/Dart-Code#5602 Change-Id: I52bf113b832446da1b672d949d0fc3c2f6d018bf Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/466101 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 1da50ff commit ff5706e

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

pkg/analysis_server/lib/src/lsp/handlers/handler_format_on_type.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ class FormatOnTypeHandler
128128
// Bodies
129129
EmptyClassBody(:var semicolon) ||
130130
EmptyFunctionBody(:var semicolon) ||
131-
EnumBody(:var semicolon?) ||
132131
ExpressionFunctionBody(:var semicolon?) ||
133132
NativeFunctionBody(:var semicolon) ||
134133
// Declarations

pkg/analysis_server/test/lsp/format_test.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,16 @@ void f ()
253253
''', isNull);
254254
}
255255

256+
/// Ensure the semicolon after enum constants does not trigger formatting
257+
/// because the formatter removes it if there is nothing after it.
258+
///
259+
/// https://github.com/dart-lang/sdk/issues/61909
260+
Future<void> test_formatOnType_bad_semiColon_enumBodySeparator() async {
261+
await expectFormatOnTypeResult('''
262+
enum E { a, b[!;!] }
263+
''', isNull);
264+
}
265+
256266
Future<void> test_formatOnType_bad_semicolon_inComment() async {
257267
await expectFormatOnTypeResult('''
258268
void f ()
@@ -318,6 +328,17 @@ void f ()
318328
''', isNotNull);
319329
}
320330

331+
Future<void> test_formatOnType_good_semiColon_enumConstructor() async {
332+
await expectFormatOnTypeResult('''
333+
enum X {
334+
a,
335+
b;
336+
337+
const X()[!;!]
338+
}
339+
''', isNotNull);
340+
}
341+
321342
Future<void> test_formatOnType_good_semicolon_statementEnd() async {
322343
await expectFormatOnTypeResult('''
323344
void f ()

0 commit comments

Comments
 (0)