[DAP] Add a custom event to pass flutter.serviceExtensionStateChanged… (#93870)

This commit is contained in:
Danny Tuppeny
2021-11-23 04:12:33 +00:00
committed by GitHub
parent fae84f6714
commit 77fca35877
4 changed files with 111 additions and 1 deletions

View File

@@ -66,4 +66,19 @@ Some custom requests are available for clients to call. Below are the Flutter-sp
## Custom Events
The debug adapter may emit several custom events that are useful to clients. There are not currently any custom Flutter events, but the standard Dart DAP custom requests are [documented here](https://github.com/dart-lang/sdk/blob/main/pkg/dds/tool/dap/README.md#custom-events).
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.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.
```
{
"type": "event",
"event": "flutter.serviceExtensionStateChanged",
"body": {
"extension": "ext.flutter.debugPaint",
"value": "true",
}
}
```

View File

@@ -145,6 +145,21 @@ class FlutterDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArguments
terminatePids(ProcessSignal.sigkill);
}
@override
Future<void> handleExtensionEvent(vm.Event event) async {
await super.handleExtensionEvent(event);
switch (event.kind) {
case vm.EventKind.kExtension:
switch (event.extensionKind) {
case 'Flutter.ServiceExtensionStateChanged':
_sendServiceExtensionStateChanged(event.extensionData);
break;
}
break;
}
}
/// Called by [launchRequest] to request that we actually start the app to be run/debugged.
///
/// For debugging, this should start paused, connect to the VM Service, set
@@ -445,4 +460,14 @@ class FlutterDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArguments
sendOutput('console', 'Failed to $action: $error');
}
}
void _sendServiceExtensionStateChanged(vm.ExtensionData? extensionData) {
final Map<String, dynamic>? data = extensionData?.data;
if (data != null) {
sendEvent(
RawEventBody(data),
eventType: 'flutter.serviceExtensionStateChanged',
);
}
}
}