[analysis_server] Fix "Move Top Level" when multi-selection includes an unnamed extension

Fixes https://github.com/dart-lang/sdk/issues/53888

Change-Id: I034473d3a37b835c5dd81b76950b4b46d2cbc59d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332428
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Danny Tuppeny 2024-02-05 22:32:58 +00:00 committed by Commit Queue
parent 8473e65472
commit 7e8ba2a708
2 changed files with 29 additions and 1 deletions

View file

@ -238,7 +238,7 @@ class MoveTopLevelToFile extends RefactoringProducer {
} else if (node is EnumDeclaration && validSelection(node.name)) {
name = node.name.lexeme;
} else if (node is ExtensionDeclaration && validSelection(node.name)) {
name = node.name!.lexeme;
name = node.name?.lexeme;
} else if (node is FunctionDeclaration &&
node.parent is CompilationUnit &&
validSelection(node.name)) {

View file

@ -1122,6 +1122,34 @@ class B {}
);
}
Future<void> test_multiple_withUnnamedExtension() async {
var originalSource = '''
class A {}
[!class ClassToMove1 {}
extension on Int {}
class ClassToMove2 {}!]
class B {}
''';
var expected = '''
>>>>>>>>>> lib/class_to_move1.dart created
class ClassToMove1 {}
extension on Int {}
class ClassToMove2 {}
>>>>>>>>>> lib/main.dart
class A {}
class B {}
''';
await _multipleDeclarations(
originalSource: originalSource,
expected: expected,
count: 3,
);
}
Future<void> test_none_comment() async {
addTestSource('''
// Comm^ent