[flutter_tools] [DAP] Don't try to restart/reload if app hasn't started yet (#128267)

The editor is set to hot-reload-on-save by default so saving while the debug session is starting currently prints an error:

Failed to Hot Reload: app 'null' not found

![image](https://github.com/flutter/flutter/assets/1078012/a125b455-a46d-4993-98d8-5d8ae7237a00)

This change skips the call to `app.restart` if the app hasn't started yet to avoid printing an error.
This commit is contained in:
Danny Tuppeny 2023-06-09 10:41:07 +01:00 committed by GitHub
parent 6d4c4d75bf
commit 46007d61d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View File

@ -663,6 +663,12 @@ class FlutterDebugAdapter extends FlutterBaseDebugAdapter {
bool fullRestart, [
String? reason,
]) async {
// Don't do anything if the app hasn't started yet, as restarts and reloads
// can only operate on a running app.
if (_appId == null) {
return;
}
final String progressId = fullRestart ? 'hotRestart' : 'hotReload';
final String progressMessage = fullRestart ? 'Hot restarting…' : 'Hot reloading…';
final DapProgressReporter progress = startProgressNotification(

View File

@ -186,6 +186,30 @@ void main() {
expect(adapter.dapToFlutterRequests, isNot(contains('app.stop')));
});
test('does not call "app.restart" before app has been started', () async {
final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter(
fileSystem: MemoryFileSystem.test(style: fsStyle),
platform: platform,
simulateAppStarted: false,
);
final Completer<void> launchCompleter = Completer<void>();
final FlutterLaunchRequestArguments launchArgs = FlutterLaunchRequestArguments(
cwd: '/project',
program: 'foo.dart',
);
final Completer<void> restartCompleter = Completer<void>();
final RestartArguments restartArgs = RestartArguments();
await adapter.configurationDoneRequest(MockRequest(), null, () {});
await adapter.launchRequest(MockRequest(), launchArgs, launchCompleter.complete);
await launchCompleter.future;
await adapter.restartRequest(MockRequest(), restartArgs, restartCompleter.complete);
await restartCompleter.future;
expect(adapter.dapToFlutterRequests, isNot(contains('app.restart')));
});
test('includes Dart Debug extension progress update', () async {
final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter(
fileSystem: MemoryFileSystem.test(style: fsStyle),