repl function
Future
repl(
- VmService vmService
)
Implementation
Future repl(VmService vmService) async {
// Get currently running VM
vms = vmService;
final vm = await vmService.getVM();
final isolateRef = vm.isolates?.first;
if (isolateRef == null) {
throw Exception("unable to get reference to current Isolate");
}
if (isolateRef.id == null) {
throw Exception("unable to get ID for current Isolate");
}
isolateId = isolateRef.id!;
final isolate = await vmService.getIsolate(isolateId);
scratch = File(scratchPath);
if (!scratch.existsSync()) {
throw InvalidPathResult();
}
nextScratch = File(nextPath);
// clear out any previous code from previous sessions
scratch.writeAsStringSync('');
nextScratch.writeAsStringSync('');
// unfortuntely Repl validator func can't be async so we need to handle validation ourselves when
// we process possible statement inputs
final repl = Repl(prompt: '> ', continuation: '... ', validator: null);
for (final replInput in repl.run()) {
if (replInput.trim().isNotEmpty) {
await process(vmService, isolate, replInput);
}
}
exit(0);
}