customRequest method

  1. @override
Future<void> customRequest(
  1. Request request,
  2. RawRequestArguments? args,
  3. void sendResponse(
    1. Object?
    )
)

customRequest handles any messages that do not match standard messages in the spec.

This is used to allow a client/DA to have custom methods outside of the spec. It is up to the client/DA to negotiate which custom messages are allowed.

Implementations of this method must call super for any requests they are not handling. The base implementation will reject the request as unknown.

Custom message starting with _ are considered internal and are liable to change without warning.

Implementation

@override
Future<void> customRequest(
  Request request,
  RawRequestArguments? args,
  void Function(Object?) sendResponse,
) async {
  switch (request.command) {
    // Used by tests to validate available protocols (e.g. DDS). There may be
    // value in making this available to clients in future, but for now it's
    // internal.
    case '_getSupportedProtocols':
      final protocols = await vmService?.getSupportedProtocols();
      sendResponse(protocols?.toJson());
      break;

    // Used to toggle debug settings such as whether SDK/Packages are
    // debuggable while the session is in progress.
    case 'updateDebugOptions':
      if (args != null) {
        await _updateDebugOptions(args.args);
      }
      sendResponse(_noResult);
      break;

    // Allows an editor to call a service/service extension that it was told
    // about via a custom 'dart.serviceRegistered' or
    // 'dart.serviceExtensionAdded' event.
    case 'callService':
      final method = args?.args['method'] as String?;
      if (method == null) {
        throw DebugAdapterException(
          'Method is required to call services/service extensions',
        );
      }
      final params = args?.args['params'] as Map<String, Object?>?;
      final response = await vmService?.callServiceExtension(
        method,
        args: params,
      );
      sendResponse(response?.json);
      break;

    // Used to reload sources for all isolates. This supports Hot Reload for
    // Dart apps. Flutter's DAP handles this command itself (and sends it
    // through the run daemon) as it needs to perform additional work to
    // rebuild widgets afterwards.
    case 'hotReload':
      await isolateManager.reloadSources();
      sendResponse(_noResult);
      break;

    // Called by VS Code extension to have us force a re-evaluation of
    // variables if settings are modified that globally change the format
    // of numbers (in the case where format specifiers are not explicitly
    // provided, such as the Variables pane).
    case '_invalidateAreas':
      // We just send the invalidate request back to the client. DAP only
      // allows these to originate in the DAP server, but we have case where
      // the client knows that these have become stale (because the user
      // changed some config) so we have to bounce it through the server.
      final areas = args?.args['areas'] as List<Object?>?;
      final stringArears = areas?.whereType<String>().toList();
      // Trigger the invalidation.
      sendEvent(InvalidatedEventBody(areas: stringArears));
      // Respond to the incoming request.
      sendResponse(_noResult);
      break;

    default:
      await super.customRequest(request, args, sendResponse);
  }
}