use crate::Span;
#[derive(Debug, Clone)]
pub struct Diagnostic {
pub kind: DiagnosticKind,
pub message: String,
pub span: Option<Span>,
pub notes: Vec<DiagnosticNote>,
pub helps: Vec<DiagnosticHelp>,
}
#[derive(Debug, Clone)]
pub struct DiagnosticNote {
pub message: String,
pub span: Option<Span>,
}
#[derive(Debug, Clone)]
pub struct DiagnosticHelp {
pub message: String,
pub span: Option<Span>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DiagnosticKind {
Error,
Warning,
}
impl Diagnostic {
pub fn new_error(message: impl Into<String>, span: Option<Span>) -> Self {
Self {
kind: DiagnosticKind::Error,
message: message.into(),
span,
notes: Vec::new(),
helps: Vec::new(),
}
}
pub fn new_warning(message: impl Into<String>, span: Option<Span>) -> Self {
Self {
kind: DiagnosticKind::Warning,
message: message.into(),
span,
notes: Vec::new(),
helps: Vec::new(),
}
}
pub fn add_note(&mut self, message: impl Into<String>, span: Option<Span>) {
self.notes.push(DiagnosticNote {
message: message.into(),
span,
});
}
pub fn add_help(&mut self, message: impl Into<String>, span: Option<Span>) {
self.helps.push(DiagnosticHelp {
message: message.into(),
span,
});
}
pub fn with_note(mut self, message: impl Into<String>, span: Option<Span>) -> Self {
self.add_note(message.into(), span);
self
}
pub fn with_help(mut self, message: impl Into<String>, span: Option<Span>) -> Self {
self.add_help(message.into(), span);
self
}
}