use crate::ast::types::Identity; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum DiagnosticLevel { Error, Warning, Hint, } #[derive(Debug, Clone)] pub struct Diagnostic { pub level: DiagnosticLevel, pub message: String, pub identity: Option, } #[derive(Debug, Clone, Default)] pub struct Diagnostics { pub items: Vec, } impl Diagnostics { pub fn new() -> Self { Self { items: Vec::new() } } pub fn has_errors(&self) -> bool { self.items.iter().any(|d| d.level == DiagnosticLevel::Error) } pub fn push_error(&mut self, msg: impl Into, id: Option) { self.items.push(Diagnostic { level: DiagnosticLevel::Error, message: msg.into(), identity: id, }); } pub fn push_warning(&mut self, msg: impl Into, id: Option) { self.items.push(Diagnostic { level: DiagnosticLevel::Warning, message: msg.into(), identity: id, }); } pub fn push_hint(&mut self, msg: impl Into, id: Option) { self.items.push(Diagnostic { level: DiagnosticLevel::Hint, message: msg.into(), identity: id, }); } }