use crate::ast::Span;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum Severity {
Error,
Warning,
Advisory,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Diagnostic {
pub code: String,
pub severity: Severity,
pub message: String,
pub span: Option<Span>,
pub subject_id: Option<String>,
}
impl Diagnostic {
pub fn new(
code: impl Into<String>,
severity: Severity,
message: impl Into<String>,
span: Option<Span>,
subject_id: Option<String>,
) -> Self {
Self {
code: code.into(),
severity,
message: message.into(),
span,
subject_id,
}
}
pub fn error(
code: impl Into<String>,
message: impl Into<String>,
span: Option<Span>,
subject_id: Option<String>,
) -> Self {
Self::new(code, Severity::Error, message, span, subject_id)
}
pub fn warning(
code: impl Into<String>,
message: impl Into<String>,
span: Option<Span>,
subject_id: Option<String>,
) -> Self {
Self::new(code, Severity::Warning, message, span, subject_id)
}
pub fn advisory(
code: impl Into<String>,
message: impl Into<String>,
span: Option<Span>,
subject_id: Option<String>,
) -> Self {
Self::new(code, Severity::Advisory, message, span, subject_id)
}
}