[analyzer] Add LSP integration test for diagnostic context messages
See https://github.com/dart-lang/sdk/issues/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>
This commit is contained in:
committed by
commit-bot@chromium.org
parent
b173c18796
commit
65050020f5
@@ -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;');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user