use crate::source::SourceSpan;
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct DiagnosticCode(&'static str);
impl DiagnosticCode {
#[must_use]
pub const fn as_str(self) -> &'static str {
self.0
}
pub(crate) const fn new(value: &'static str) -> Self {
Self(value)
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Severity {
Error,
Warning,
Note,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Label {
span: SourceSpan,
message: &'static str,
}
impl Label {
pub(crate) const fn new(span: SourceSpan, message: &'static str) -> Self {
Self { span, message }
}
#[must_use]
pub const fn span(&self) -> SourceSpan {
self.span
}
#[must_use]
pub const fn message(&self) -> &'static str {
self.message
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Diagnostic {
code: DiagnosticCode,
severity: Severity,
summary: &'static str,
labels: Vec<Label>,
}
impl Diagnostic {
pub(crate) fn new(code: DiagnosticCode, severity: Severity, summary: &'static str, label: Label) -> Self {
Self {
code,
severity,
summary,
labels: vec![label],
}
}
#[must_use]
pub const fn code(&self) -> DiagnosticCode {
self.code
}
#[must_use]
pub const fn severity(&self) -> Severity {
self.severity
}
#[must_use]
pub const fn summary(&self) -> &'static str {
self.summary
}
#[must_use]
pub fn labels(&self) -> &[Label] {
&self.labels
}
}