[flutter_tools/dap] Inform DAP client whether restart is supported (#121610)
[flutter_tools/dap] Inform DAP client whether restart is supported
This commit is contained in:
@@ -48,13 +48,6 @@ class FlutterDebugAdapter extends FlutterBaseDebugAdapter {
|
||||
/// their handlers.
|
||||
final Map<int, Completer<Object?>> _flutterRequestCompleters = <int, Completer<Object?>>{};
|
||||
|
||||
/// Whether or not this adapter can handle the restartRequest.
|
||||
///
|
||||
/// For Flutter apps we can handle this with a Hot Restart rather than having
|
||||
/// the whole debug session stopped and restarted.
|
||||
@override
|
||||
bool get supportsRestartRequest => true;
|
||||
|
||||
/// A list of reverse-requests from `flutter run --machine` that should be forwarded to the client.
|
||||
static const Set<String> _requestsToForwardToClient = <String>{
|
||||
// The 'app.exposeUrl' request is sent by Flutter to request the client
|
||||
@@ -399,6 +392,12 @@ class FlutterDebugAdapter extends FlutterBaseDebugAdapter {
|
||||
if (_appId == null) {
|
||||
throw DebugAdapterException('Unexpected null `appId` in app.start event');
|
||||
}
|
||||
|
||||
// Notify the client whether it can call 'restartRequest' when the user
|
||||
// clicks restart, instead of terminating and re-starting its own debug
|
||||
// session (which is much slower, but required for profile/release mode).
|
||||
final bool supportsRestart = (params['supportsRestart'] as bool?) ?? false;
|
||||
sendEvent(CapabilitiesEventBody(capabilities: Capabilities(supportsRestartRequest: supportsRestart)));
|
||||
}
|
||||
|
||||
/// Handles the app.started event from Flutter.
|
||||
|
||||
@@ -101,6 +101,44 @@ void main() {
|
||||
expect(adapter.pidsToTerminate, isNot(contains(123)));
|
||||
});
|
||||
|
||||
|
||||
group('supportsRestartRequest', () {
|
||||
void testRestartSupport(bool supportsRestart) {
|
||||
test('notifies client for supportsRestart: $supportsRestart', () async {
|
||||
final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter(
|
||||
fileSystem: MemoryFileSystem.test(style: fsStyle),
|
||||
platform: platform,
|
||||
supportsRestart: supportsRestart,
|
||||
);
|
||||
|
||||
final FlutterLaunchRequestArguments args = FlutterLaunchRequestArguments(
|
||||
cwd: '/project',
|
||||
program: 'foo.dart',
|
||||
);
|
||||
|
||||
// Listen for a Capabilities event that modifies 'supportsRestartRequest'.
|
||||
final Future<CapabilitiesEventBody> capabilitiesUpdate = adapter
|
||||
.dapToClientMessages
|
||||
.where((Map<String, Object?> message) => message['event'] == 'capabilities')
|
||||
.map((Map<String, Object?> message) => message['body'] as Map<String, Object?>?)
|
||||
.where((Map<String, Object?>? body) => body != null).cast<Map<String, Object?>>()
|
||||
.map(CapabilitiesEventBody.fromJson)
|
||||
.firstWhere((CapabilitiesEventBody body) => body.capabilities.supportsRestartRequest != null);
|
||||
|
||||
await adapter.configurationDoneRequest(MockRequest(), null, () {});
|
||||
final Completer<void> launchCompleter = Completer<void>();
|
||||
await adapter.launchRequest(MockRequest(), args, launchCompleter.complete);
|
||||
await launchCompleter.future;
|
||||
|
||||
// Ensure the Capabilities update has the expected value.
|
||||
expect((await capabilitiesUpdate).capabilities.supportsRestartRequest, supportsRestart);
|
||||
});
|
||||
}
|
||||
|
||||
testRestartSupport(true);
|
||||
testRestartSupport(false);
|
||||
});
|
||||
|
||||
test('calls "app.stop" on terminateRequest', () async {
|
||||
final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter(
|
||||
fileSystem: MemoryFileSystem.test(style: fsStyle),
|
||||
|
||||
@@ -18,6 +18,7 @@ class MockFlutterDebugAdapter extends FlutterDebugAdapter {
|
||||
required FileSystem fileSystem,
|
||||
required Platform platform,
|
||||
bool simulateAppStarted = true,
|
||||
bool supportsRestart = true,
|
||||
FutureOr<void> Function(MockFlutterDebugAdapter adapter)? preAppStart,
|
||||
}) {
|
||||
final StreamController<List<int>> stdinController = StreamController<List<int>>();
|
||||
@@ -31,6 +32,7 @@ class MockFlutterDebugAdapter extends FlutterDebugAdapter {
|
||||
fileSystem: fileSystem,
|
||||
platform: platform,
|
||||
simulateAppStarted: simulateAppStarted,
|
||||
supportsRestart: supportsRestart,
|
||||
preAppStart: preAppStart,
|
||||
);
|
||||
}
|
||||
@@ -41,6 +43,7 @@ class MockFlutterDebugAdapter extends FlutterDebugAdapter {
|
||||
required super.fileSystem,
|
||||
required super.platform,
|
||||
this.simulateAppStarted = true,
|
||||
this.supportsRestart = true,
|
||||
this.preAppStart,
|
||||
}) {
|
||||
clientChannel.listen((ProtocolMessage message) {
|
||||
@@ -51,6 +54,7 @@ class MockFlutterDebugAdapter extends FlutterDebugAdapter {
|
||||
int _seq = 1;
|
||||
final ByteStreamServerChannel clientChannel;
|
||||
final bool simulateAppStarted;
|
||||
final bool supportsRestart;
|
||||
final FutureOr<void> Function(MockFlutterDebugAdapter adapter)? preAppStart;
|
||||
|
||||
late String executable;
|
||||
@@ -110,6 +114,7 @@ class MockFlutterDebugAdapter extends FlutterDebugAdapter {
|
||||
'event': 'app.start',
|
||||
'params': <String, Object?>{
|
||||
'appId': 'TEST',
|
||||
'supportsRestart': supportsRestart,
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user