captureToolEvents function
Sends everything postToolEvent posts to heard instead of the VM
service, until the returned Registration is cancelled, which puts the
VM service back.
final posted = <String>[];
addTearDown(captureToolEvents((kind, data) => posted.add(kind)).cancel);
Implementation
Registration captureToolEvents(ToolEventPoster heard) {
final before = toolEventCapture;
toolEventCapture = heard;
return Registration(() => toolEventCapture = before);
}