use std::sync::Arc;
use miette::NamedSource;
use crate::ParserError;
#[derive(Debug, thiserror::Error, miette::Diagnostic)]
#[error("{inner}")]
#[diagnostic(forward(inner))]
pub struct DiagnosticReport {
#[source_code]
source_code: Arc<NamedSource<Arc<str>>>,
inner: ParserError,
}
impl DiagnosticReport {
#[must_use]
pub fn new(error: ParserError, source: Arc<str>, label: impl Into<String>) -> Self {
Self {
source_code: Arc::new(NamedSource::new(label.into(), source)),
inner: error,
}
}
#[must_use]
pub const fn error(&self) -> &ParserError {
&self.inner
}
#[must_use]
pub fn source(&self) -> &str {
self.source_code.inner().as_ref()
}
#[must_use]
pub fn named_source(&self) -> &NamedSource<Arc<str>> {
&self.source_code
}
}