extractVmUriFromLog function

String? extractVmUriFromLog(
  1. String text
)

Scans text for a Dart VM service URI and returns the normalised HTTP URL, or null if none is found.

Searches in reverse order (most-recent line wins) and prefers the [FDB_VM_URI] marker emitted by fdb_helper over Flutter engine lines.

Exposed as a top-level function so it can be unit-tested independently of the process-spawning discovery functions.

Implementation

String? extractVmUriFromLog(String text) {
  final lines = text.split('\n');

  // First pass: prefer the stable [FDB_VM_URI] marker.
  for (final line in lines.reversed) {
    final m = _vmUriPatterns[0].firstMatch(line);
    if (m != null) return _normalizeUri(m.group(1)!.trimRight());
  }

  // Second pass: fall back to Flutter engine output patterns.
  for (final line in lines.reversed) {
    for (final pattern in _vmUriPatterns.skip(1)) {
      final m = pattern.firstMatch(line);
      if (m != null) return _normalizeUri(m.group(1)!.trimRight());
    }
  }

  return null;
}