split out some responsibilities from DiagnosticsReporter and added some tests for it.