Skip to content

Commit eb057fe

Browse files
bwilkersoncommit-bot@chromium.org
authored andcommitted
Send the correction as part of the diagnostic message in LSP
Change-Id: I894c90b7a895d36c3e9bee7623d1301c8c390b69 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/109740 Commit-Queue: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Danny Tuppeny <dantup@google.com>
1 parent 3d5238a commit eb057fe

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

pkg/analysis_server/lib/src/lsp/mapping.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,12 +644,17 @@ lsp.Diagnostic toDiagnostic(
644644
.toList();
645645
}
646646

647+
String message = error.message;
648+
if (error.correctionMessage != null) {
649+
message = '$message\n${error.correctionMessage}';
650+
}
651+
647652
return new lsp.Diagnostic(
648653
toRange(result.lineInfo, error.offset, error.length),
649654
toDiagnosticSeverity(errorSeverity),
650655
errorCode.name.toLowerCase(),
651656
languageSourceName,
652-
error.message,
657+
message,
653658
relatedInformation,
654659
);
655660
}

pkg/analysis_server/test/lsp/diagnostic_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,21 @@ void f() {
5050
expect(diagnostic.relatedInformation, hasLength(1));
5151
}
5252

53+
test_correction() async {
54+
newFile(mainFilePath, content: '''
55+
void f() {
56+
x = 0;
57+
}
58+
''');
59+
60+
final diagnosticsUpdate = waitForDiagnostics(mainFileUri);
61+
await initialize();
62+
final diagnostics = await diagnosticsUpdate;
63+
expect(diagnostics, hasLength(1));
64+
final diagnostic = diagnostics.first;
65+
expect(diagnostic.message, contains('\nTry'));
66+
}
67+
5368
test_deletedFile() async {
5469
newFile(mainFilePath, content: 'String a = 1;');
5570

0 commit comments

Comments
 (0)