setBreakpointsRequest method

  1. @override
Future<void> setBreakpointsRequest(
  1. Request request,
  2. SetBreakpointsArguments args,
  3. void sendResponse(
    1. SetBreakpointsResponseBody
    )
)

Handles a request from the client to set breakpoints.

This method can be called at any time (before the app is launched or while the app is running) and will include the new full set of breakpoints for the file URI in args.source.path.

The VM requires breakpoints to be set per-isolate so these will be passed to isolateManager that will fan them out to each isolate.

When new isolates are registered, it is isolateManager's responsibility to ensure all breakpoints are given to them (and like at startup, this must happen before they are resumed).

Implementation

@override
Future<void> setBreakpointsRequest(
  Request request,
  SetBreakpointsArguments args,
  void Function(SetBreakpointsResponseBody) sendResponse,
) async {
  final breakpoints = args.breakpoints ?? [];

  final path = args.source.path;
  final name = args.source.name;
  final uri = path != null
      ? normalizeUri(fromClientPathOrUri(path)).toString()
      : name!;

  // Use a completer to track when the response is sent, so any events related
  // to these breakpoints are not sent before the client has the IDs.
  final completer = Completer<void>();

  final clientBreakpoints = breakpoints
      .map((bp) => ClientBreakpoint(bp, completer.future))
      .toList();
  await isolateManager.setBreakpoints(uri, clientBreakpoints);

  sendResponse(SetBreakpointsResponseBody(
    breakpoints: clientBreakpoints
        // Send breakpoints back as unverified and with our generated IDs so we
        // can update them with a 'breakpoint' event when we get the
        // 'BreakpointAdded'/'BreakpointResolved' events from the VM.
        .map((bp) => Breakpoint(id: bp.id, verified: false))
        .toList(),
  ));
  completer.complete();
}