convertUriToOrgDartlangSdk method
Converts a file URI inside the current SDK root into a URI in the form org-dartlang-sdk:///sdk/lib/collection/hash_set.dart.
Implementation
Uri? convertUriToOrgDartlangSdk(Uri input) {
// TODO(dantup): We may need to expand this if we start using
// macro-generated files in the SDK.
if (!input.isScheme('file')) {
return null;
}
final inputPath = input.toFilePath();
for (final mapping in orgDartlangSdkMappings.entries) {
final mapPath = mapping.key;
final mapUri = mapping.value;
if (path.isWithin(mapPath, inputPath)) {
final relative = path.relative(inputPath, from: mapPath);
return Uri(
scheme: mapUri.scheme,
host: '',
pathSegments: [...mapUri.pathSegments, ...path.split(relative)],
);
}
}
return null;
}