Unverified Commit 46007d61 authored by Danny Tuppeny's avatar Danny Tuppeny Committed by GitHub

[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.
parent 6d4c4d75
......@@ -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(
......
......@@ -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),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment