resolveToolEventUris method
Resolves any URI stored in data
with key field
to a local file URI via
the VM Service and adds it to data
with a 'resolved' prefix.
A resolved URI will not be added if the URI cannot be resolved or is already a 'file://' URI.
Implementation
Future<void> resolveToolEventUris(
vm.IsolateRef? isolate,
Map<String, Object?> data,
String field,
) async {
final thread = isolateManager.threadForIsolate(isolate);
if (thread == null) {
return;
}
final uriString = data[field];
if (uriString is! String) {
return;
}
final uri = Uri.tryParse(uriString);
if (uri == null) {
return;
}
// Doesn't need resolving if already file-like.
if (isSupportedFileScheme(uri)) {
return;
}
final fileLikeUri = await thread.resolveUriToPath(uri);
if (fileLikeUri != null) {
// Convert:
// uri -> resolvedUri
// fileUri -> resolvedFileUri
final resolvedFieldName =
'resolved${field.substring(0, 1).toUpperCase()}${field.substring(1)}';
data[resolvedFieldName] = fileLikeUri.toString();
}
}