mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 16:41:07 +00:00
[analysis_server] Add additional tests for file delete/create with overlays
Change-Id: Iec6a158f394611a84bce6e4bf107039fbf82241e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/325340 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
f2eee8bf71
commit
ccbc3d95dc
|
@ -755,6 +755,61 @@ analyzer:
|
|||
_assertAnalyzedFiles(hasErrors: [], notAnalyzed: [path]);
|
||||
}
|
||||
|
||||
/// Tests that deleting and re-creating a file while an overlay is active
|
||||
/// keeps the diagnotics when the overlay is then removed, then removes them
|
||||
/// when the file is deleted.
|
||||
///
|
||||
/// https://github.com/dart-lang/sdk/issues/53475
|
||||
Future<void> test_fileSystem_deleteFile_createFile_withOverlay_dart() async {
|
||||
var a_path = convertPath('$testPackageLibPath/a.dart');
|
||||
|
||||
_createFilesWithErrors([a_path]);
|
||||
|
||||
await setRoots(included: [workspaceRootPath], excluded: []);
|
||||
await server.onAnalysisComplete;
|
||||
|
||||
// Initial file has errors.
|
||||
assertHasErrors(a_path);
|
||||
|
||||
// Overlay still has errors.
|
||||
await handleSuccessfulRequest(
|
||||
AnalysisUpdateContentParams({
|
||||
a_path: AddContentOverlay('error'),
|
||||
}).toRequest('0'),
|
||||
);
|
||||
await pumpEventQueue();
|
||||
await server.onAnalysisComplete;
|
||||
assertHasErrors(a_path);
|
||||
|
||||
// After deleting the file, still has errors.
|
||||
deleteFile(a_path);
|
||||
await pumpEventQueue();
|
||||
await server.onAnalysisComplete;
|
||||
assertHasErrors(a_path);
|
||||
|
||||
// After re-creating the file, still has errors.
|
||||
_createFilesWithErrors([a_path]);
|
||||
await pumpEventQueue();
|
||||
await server.onAnalysisComplete;
|
||||
assertHasErrors(a_path);
|
||||
|
||||
// After removing the overlay, still has errors.
|
||||
await handleSuccessfulRequest(
|
||||
AnalysisUpdateContentParams({
|
||||
a_path: RemoveContentOverlay(),
|
||||
}).toRequest('1'),
|
||||
);
|
||||
await pumpEventQueue();
|
||||
await server.onAnalysisComplete;
|
||||
assertHasErrors(a_path);
|
||||
|
||||
// After deleting the file again, errors are now gone.
|
||||
deleteFile(a_path);
|
||||
await pumpEventQueue();
|
||||
await server.onAnalysisComplete;
|
||||
assertNoErrorsNotification(a_path);
|
||||
}
|
||||
|
||||
Future<void> test_fileSystem_deleteFile_dart() async {
|
||||
var a_path = '$testPackageLibPath/a.dart';
|
||||
|
||||
|
@ -873,6 +928,10 @@ void f(A a) {}
|
|||
assertNoErrorsNotification(a_path);
|
||||
}
|
||||
|
||||
/// Tests that deleting a file does not clear diagnostics if there's still
|
||||
/// an active overlay for the file.
|
||||
///
|
||||
/// https://github.com/dart-lang/sdk/issues/53475
|
||||
Future<void> test_fileSystem_deleteFile_withOverlay_dart() async {
|
||||
var a_path = convertPath('$testPackageLibPath/a.dart');
|
||||
|
||||
|
@ -894,13 +953,13 @@ void f(A a) {}
|
|||
await server.onAnalysisComplete;
|
||||
assertHasErrors(a_path);
|
||||
|
||||
// After deleting files, still has errors.
|
||||
// After deleting the file, still has errors.
|
||||
deleteFile(a_path);
|
||||
await pumpEventQueue();
|
||||
await server.onAnalysisComplete;
|
||||
assertHasErrors(a_path);
|
||||
|
||||
// After removing overlay, errors are gone.
|
||||
// After removing the overlay, errors are gone.
|
||||
await handleSuccessfulRequest(
|
||||
AnalysisUpdateContentParams({
|
||||
a_path: RemoveContentOverlay(),
|
||||
|
|
|
@ -168,7 +168,7 @@ class Bar {
|
|||
equals(content));
|
||||
}
|
||||
|
||||
/// Checks that deleting a file does not clear diagnostics while there's an
|
||||
/// Tests that deleting a file does not clear diagnostics while there's an
|
||||
/// overlay, and that removing the overlay later clears the diagnostics.
|
||||
///
|
||||
/// https://github.com/dart-lang/sdk/issues/53475
|
||||
|
@ -197,13 +197,62 @@ class Bar {
|
|||
await pumpEventQueue(times: 5000);
|
||||
expect(latestDiagnostics[mainFilePath], isNotEmpty);
|
||||
|
||||
// Expect diagnostics to be removed after we cloes the file (which removes
|
||||
// Expect diagnostics to be removed after we close the file (which removes
|
||||
// the overlay).
|
||||
await closeFile(mainFileUri);
|
||||
await pumpEventQueue(times: 5000);
|
||||
expect(latestDiagnostics[mainFilePath], isEmpty);
|
||||
}
|
||||
|
||||
/// Tests that deleting and re-creating a file while an overlay is active
|
||||
/// keeps the diagnotics when the overlay is then removed, then removes them
|
||||
/// when the file is deleted.
|
||||
///
|
||||
/// https://github.com/dart-lang/sdk/issues/53475
|
||||
Future<void>
|
||||
test_documentOpen_fileDeleted_fileCreated_documentClosed_fileDeleted() async {
|
||||
const content = 'error';
|
||||
newFile(mainFilePath, content);
|
||||
|
||||
// Track the latest diagnostics as the client would.
|
||||
Map<String, List<Diagnostic>> latestDiagnostics = {};
|
||||
trackDiagnostics(latestDiagnostics);
|
||||
|
||||
// Expect diagnostics after initial analysis because file has invalid
|
||||
// content.
|
||||
await initialize();
|
||||
await pumpEventQueue(times: 5000);
|
||||
expect(latestDiagnostics[mainFilePath], isNotEmpty);
|
||||
|
||||
// Expect diagnostics after opening the file with the same contents.
|
||||
await openFile(mainFileUri, content);
|
||||
await pumpEventQueue(times: 5000);
|
||||
expect(latestDiagnostics[mainFilePath], isNotEmpty);
|
||||
|
||||
// Expect diagnostics after deleting the file because the overlay is still
|
||||
// active.
|
||||
deleteFile(mainFilePath);
|
||||
await pumpEventQueue(times: 5000);
|
||||
expect(latestDiagnostics[mainFilePath], isNotEmpty);
|
||||
|
||||
// Expect diagnostics remain after re-creating the file (the overlay is still
|
||||
// active).
|
||||
newFile(mainFilePath, content);
|
||||
await pumpEventQueue(times: 5000);
|
||||
expect(latestDiagnostics[mainFilePath], isNotEmpty);
|
||||
|
||||
// Expect diagnostics remain after we close the file because the file still
|
||||
//exists on disk.
|
||||
await closeFile(mainFileUri);
|
||||
await pumpEventQueue(times: 5000);
|
||||
expect(latestDiagnostics[mainFilePath], isNotEmpty);
|
||||
|
||||
// Finally, expect deleteing the file clears the diagnostics.
|
||||
deleteFile(mainFilePath);
|
||||
await pumpEventQueue(times: 5000);
|
||||
expect(latestDiagnostics[mainFilePath], isEmpty);
|
||||
}
|
||||
|
||||
Future<void> test_documentOpen_notifiesPlugins() async {
|
||||
if (!AnalysisServer.supportsPlugins) return;
|
||||
await _initializeAndOpen();
|
||||
|
|
Loading…
Reference in a new issue