[analyzer] Update LSP fix-all tests based on new server implementation
Change-Id: Iccc71d67c77eb2a372293e746ca12984f67a0579
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196285
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analysis_server/test/lsp/code_actions_abstract.dart b/pkg/analysis_server/test/lsp/code_actions_abstract.dart
index 32466e9..591a70e 100644
--- a/pkg/analysis_server/test/lsp/code_actions_abstract.dart
+++ b/pkg/analysis_server/test/lsp/code_actions_abstract.dart
@@ -74,17 +74,6 @@
.toList();
}
- Future<Either2<Command, CodeAction>> getFixAllAction(
- String title, Uri uri, String content) async {
- // TODO(dantup): Fix this once new server support has landed.
- throw UnimplementedError();
- // final codeActions =
- // await getCodeActions(uri.toString(), range: rangeFromMarkers(content));
- // final fixAction =
- // findCommand(codeActions, Commands.fixAllOfErrorCodeInFile, title);
- // return fixAction;
- }
-
/// Verifies that executing the given code actions command on the server
/// results in an edit being sent in the client that updates the file to match
/// the expected content.
diff --git a/pkg/analysis_server/test/lsp/code_actions_fixes_test.dart b/pkg/analysis_server/test/lsp/code_actions_fixes_test.dart
index e0b0d8e..5b8f242 100644
--- a/pkg/analysis_server/test/lsp/code_actions_fixes_test.dart
+++ b/pkg/analysis_server/test/lsp/code_actions_fixes_test.dart
@@ -300,10 +300,7 @@
expect(fixTitle, equals("Create function 'foo'"));
}
- @failingTest
Future<void> test_fixAll_notWhenSingle() async {
- // TODO(dantup): Fix the text used to locate the fix once the
- // new server support has landed.
const content = '''
void f(String a) {
[[print(a!)]];
@@ -316,17 +313,16 @@
emptyTextDocumentClientCapabilities, [CodeActionKind.QuickFix]),
);
- final fixAction = await getFixAllAction(
- "Apply all: Remove the '!'", mainFileUri, content);
+ final codeActions = await getCodeActions(mainFileUri.toString(),
+ range: rangeFromMarkers(content));
+ final fixAction = findEditAction(
+ codeActions, CodeActionKind('quickfix'), "Remove '!'s in file");
// Should not appear if there was only a single error.
expect(fixAction, isNull);
}
- @failingTest
Future<void> test_fixAll_whenMultiple() async {
- // TODO(dantup): Fix this test up to use the new server support for
- // fix-all-in-file once landed.
const content = '''
void f(String a) {
[[print(a!!)]];
@@ -346,11 +342,17 @@
emptyTextDocumentClientCapabilities, [CodeActionKind.QuickFix]),
);
- final fixAction = await getFixAllAction(
- "Apply all: Remove the '!'", mainFileUri, content);
+ final codeActions = await getCodeActions(mainFileUri.toString(),
+ range: rangeFromMarkers(content));
+ final fixAction = findEditAction(
+ codeActions, CodeActionKind('quickfix'), "Remove '!'s in file")!;
- await verifyCodeActionEdits(
- fixAction, withoutMarkers(content), expectedContent);
+ // Ensure applying the changes will give us the expected content.
+ final contents = {
+ mainFilePath: withoutMarkers(content),
+ };
+ applyChanges(contents, fixAction.edit!.changes!);
+ expect(contents[mainFilePath], equals(expectedContent));
}
Future<void> test_noDuplicates_differentFix() async {