use crate::{Diagnostic, SourceCache, SourceSnapshot};
#[derive(Debug, Clone)]
pub struct CapturedDiagnostic {
diagnostic: Diagnostic,
sources: SourceSnapshot,
}
impl CapturedDiagnostic {
pub fn new(diagnostic: Diagnostic, sources: SourceSnapshot) -> Self {
let diagnostic = diagnostic.bind_source_revisions(&sources);
Self {
diagnostic,
sources,
}
}
pub fn diagnostic(&self) -> &Diagnostic {
&self.diagnostic
}
pub fn sources(&self) -> &SourceSnapshot {
&self.sources
}
pub fn is_stale(&self, live: &SourceCache) -> bool {
self.diagnostic.has_stale_sources(live)
}
pub fn is_current(&self, live: &SourceCache) -> bool {
!self.is_stale(live)
}
pub fn into_parts(self) -> (Diagnostic, SourceSnapshot) {
(self.diagnostic, self.sources)
}
pub fn into_diagnostic(self) -> Diagnostic {
self.diagnostic
}
}