projectDirForVm method

Future<String?> projectDirForVm(
  1. Uri vmUri
)

Flutter project root behind a running app: the cwd of the DDS serving vmUri (its listener, or the DDS fronting that raw VM port) or of its flutter run parent, when that folder is a Flutter app.

Implementation

Future<String?> projectDirForVm(Uri vmUri) async {
  final port = vmUri.port;
  if (port == 0) return null;
  for (final start in [...(await portOwners(port)).pids, ...await _ddsPidsFronting(port)]) {
    int? pid = start;
    for (var hop = 0; pid != null && pid > 1 && hop < 3; hop++) {
      final cwd = await _cwdOf(pid);
      if (cwd != null && flutterAppProblem(cwd) == null) return cwd;
      pid = await _parentOf(pid);
    }
  }
  return null;
}