convertPathToOrgDartlangSdk method

Uri? convertPathToOrgDartlangSdk(
  1. String input
)

Converts a file path inside the current SDK root into a URI in the form org-dartlang-sdk:///sdk/lib/collection/hash_set.dart.

Implementation

Uri? convertPathToOrgDartlangSdk(String input) {
  for (final mapping in orgDartlangSdkMappings.entries) {
    final mapPath = mapping.key;
    final mapUri = mapping.value;
    if (path.isWithin(mapPath, input)) {
      final relative = path.relative(input, from: mapPath);
      return Uri(
        scheme: mapUri.scheme,
        host: '',
        pathSegments: [...mapUri.pathSegments, ...path.split(relative)],
      );
    }
  }

  return null;
}