sendOutput method

void sendOutput(
  1. String category,
  2. String message, {
  3. int? variablesReference,
  4. bool? parseStackFrames,
})

Sends an OutputEvent (without a newline, since calls to this method may be using buffered data that is not split cleanly on newlines).

If parseStackFrames is set, it controls whether to look for stack traces and extract file/line information to add to the metadata of the event. If it is null then parsing will occur only if category is "stderr".

To ensure output is sent to the client in the correct order even if processing stack frames requires async calls, this function will insert output events into a queue and only send them when previous calls have been completed.

Implementation

void sendOutput(
  String category,
  String message, {
  int? variablesReference,
  bool? parseStackFrames,
}) async {
  // Reserve our place in the queue be inserting a future that we can complete
  // after we have sent the output event.
  final completer = Completer<void>();
  final previousEvent = _lastOutputEvent ?? Future.value();
  _lastOutputEvent = completer.future;

  try {
    final outputEvents = await _buildOutputEvents(
      category,
      message,
      variablesReference: variablesReference,
      parseStackFrames: parseStackFrames,
    );

    // Chain our sends onto the end of the previous one, and complete our Future
    // once done so that the next one can go.
    await previousEvent;
    outputEvents.forEach(sendEvent);
  } finally {
    completer.complete();
  }
}