Skip to content

Commit

Permalink
[analyzer] Add LSP integration test for diagnostic context messages
Browse files Browse the repository at this point in the history
See #44907.

Change-Id: I780e584a0e624aac232439d3f87cf1fb1284ef9f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193800
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
  • Loading branch information
DanTup authored and commit-bot@chromium.org committed Apr 6, 2021
1 parent b173c18 commit 6505002
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,34 @@ void main() {

@reflectiveTest
class DiagnosticTest extends AbstractLspAnalysisServerIntegrationTest {
Future<void> test_contextMessage() async {
const content = '''
void f() {
x = 0;
int [[x]] = 1;
print(x);
}
''';
newFile(mainFilePath, content: withoutMarkers(content));

final diagnosticsUpdate = waitForDiagnostics(mainFileUri);
await initialize();
final diagnostics = await diagnosticsUpdate;

expect(diagnostics, hasLength(1));
final diagnostic = diagnostics.first;
expect(
diagnostic.message,
startsWith(
"Local variable 'x' can't be referenced before it is declared"));

expect(diagnostic.relatedInformation, hasLength(1));
final relatedInfo = diagnostic.relatedInformation.first;
expect(relatedInfo.message, equals("The declaration of 'x' is here."));
expect(relatedInfo.location.uri, equals('$mainFileUri'));
expect(relatedInfo.location.range, equals(rangeFromMarkers(content)));
}

Future<void> test_initialAnalysis() async {
newFile(mainFilePath, content: 'String a = 1;');

Expand Down

0 comments on commit 6505002

Please sign in to comment.