use crate::utils::FileId;
use codespan_reporting::*;
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum Severity {
Bug,
Error,
Warning,
}
impl std::ops::Deref for Severity {
type Target = codespan_reporting::diagnostic::Severity;
fn deref(&self) -> &Self::Target {
match self {
Severity::Bug => &diagnostic::Severity::Bug,
Severity::Error => &diagnostic::Severity::Error,
Severity::Warning => &diagnostic::Severity::Warning,
}
}
}
impl From<Severity> for diagnostic::Severity {
fn from(value: Severity) -> Self {
match value {
Severity::Bug => diagnostic::Severity::Bug,
Severity::Error => diagnostic::Severity::Error,
Severity::Warning => diagnostic::Severity::Warning,
}
}
}
pub struct Builder(diagnostic::Diagnostic<FileId>);
impl Builder {
pub fn new(severity: Severity) -> Self {
Self(diagnostic::Diagnostic::new(severity.into()))
}
pub fn title(mut self, name: impl Into<String>) -> Self {
self.0.message = name.into();
self
}
pub fn label(mut self, label: Label) -> Self {
self.0.labels.push(label.into());
self
}
pub fn note(mut self, message: impl Into<String>) -> Self {
self.0.notes.push(message.into());
self
}
}
impl std::ops::Deref for Builder {
type Target = diagnostic::Diagnostic<FileId>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl From<Builder> for diagnostic::Diagnostic<FileId> {
fn from(value: Builder) -> Self {
value.0
}
}
pub struct Label(diagnostic::Label<FileId>);
impl Label {
pub(crate) fn new(label: diagnostic::Label<FileId>) -> Self {
Self(label)
}
}
impl From<Label> for diagnostic::Label<FileId> {
fn from(value: Label) -> Self {
value.0
}
}