tryParse static method

CompletionResponse? tryParse(
  1. String text
)

Parses a response in the wire format, the inverse of format.

Returns null if text does not end with a directive line, i.e. it is not a completion response. The directive is kept as it is, including flags this version does not know.

Implementation

static CompletionResponse? tryParse(final String text) {
  final lines = LineSplitter.split(
    text,
  ).where((final line) => line.isNotEmpty).toList();
  if (lines.isEmpty) return null;
  final digits = _directiveLine.firstMatch(lines.removeLast())?[1];
  final directive = digits == null ? null : int.tryParse(digits);
  if (directive == null) return null;

  return CompletionResponse(
    [for (final line in lines) _parseCandidate(line)],
    directive: directive,
  );
}