From e2ef8cfe4486611cd4e86d3d06b5e589025ba0cf Mon Sep 17 00:00:00 2001 From: Danny Tuppeny Date: Tue, 21 Jun 2022 20:09:06 +0100 Subject: [PATCH] Pass app.started events to the DAP client + dart.debuggerUris for Profile mode (#106337) --- .../lib/src/debug_adapters/README.md | 4 +++ .../src/debug_adapters/flutter_adapter.dart | 34 +++++++++++++++---- .../debug_adapter/flutter_adapter_test.dart | 18 ++++++++++ 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/packages/flutter_tools/lib/src/debug_adapters/README.md b/packages/flutter_tools/lib/src/debug_adapters/README.md index 69ff23334f..2d426d299f 100644 --- a/packages/flutter_tools/lib/src/debug_adapters/README.md +++ b/packages/flutter_tools/lib/src/debug_adapters/README.md @@ -70,6 +70,10 @@ Some custom requests are available for clients to call. Below are the Flutter-sp The debug adapter may emit several custom events that are useful to clients. Below are the Flutter-specific custom events, and the standard Dart DAP custom events are [documented here](https://github.com/dart-lang/sdk/blob/main/pkg/dds/tool/dap/README.md#custom-events). +### `flutter.appStarted` + +This event is emitted when the application has started up. Unlike `dart.debuggerUris`, this event occurs even for `noDebug` launches or those that do not include a VM Service. + ### `flutter.serviceExtensionStateChanged` When the value of a Flutter service extension changes, this event is emitted and includes the new value. Values are always encoded as strings, even if numeric/boolean. diff --git a/packages/flutter_tools/lib/src/debug_adapters/flutter_adapter.dart b/packages/flutter_tools/lib/src/debug_adapters/flutter_adapter.dart index b4723326f1..b3947846ff 100644 --- a/packages/flutter_tools/lib/src/debug_adapters/flutter_adapter.dart +++ b/packages/flutter_tools/lib/src/debug_adapters/flutter_adapter.dart @@ -397,8 +397,25 @@ class FlutterDebugAdapter extends DartDebugAdapter{ + 'vmServiceUri': serviceUri.toString(), + }), + eventType: 'dart.debuggerUris', + ); + } } } @@ -412,6 +429,15 @@ class FlutterDebugAdapter extends DartDebugAdapter{}), + eventType: 'flutter.appStarted', + ); } /// Handles the daemon.connected event, recording the pid of the flutter_tools process. @@ -427,12 +453,6 @@ class FlutterDebugAdapter extends DartDebugAdapter params) { - // When running in noDebug mode, Flutter may still provide us a VM Service - // URI, but we will not connect it because we don't want to do any debugging. - if (!enableDebugger) { - return; - } - // Capture the VM Service URL which we'll connect to when we get app.started. final String? wsUri = params['wsUri'] as String?; if (wsUri != null) { diff --git a/packages/flutter_tools/test/integration.shard/debug_adapter/flutter_adapter_test.dart b/packages/flutter_tools/test/integration.shard/debug_adapter/flutter_adapter_test.dart index 4e63805e5d..94294b7a4f 100644 --- a/packages/flutter_tools/test/integration.shard/debug_adapter/flutter_adapter_test.dart +++ b/packages/flutter_tools/test/integration.shard/debug_adapter/flutter_adapter_test.dart @@ -302,6 +302,24 @@ void main() { await dap.client.terminate(); }); + + testWithoutContext('provides appStarted events to the client', () async { + final BasicProject project = BasicProject(); + await project.setUpIn(tempDir); + + // Launch the app and wait for it to send a 'flutter.appStarted' event. + await Future.wait(>[ + dap.client.event('flutter.appStarted'), + dap.client.start( + launch: () => dap.client.launch( + cwd: project.dir.path, + toolArgs: ['-d', 'flutter-tester'], + ), + ), + ], eagerError: true); + + await dap.client.terminate(); + }); }); group('attach', () {