use crate::common::spans::Span; #[derive(Debug, Clone)] pub enum DiagnosticLevel { Error, Warning, } #[derive(Debug, Clone)] pub struct Diagnostic { pub level: DiagnosticLevel, pub code: Option, pub message: String, pub span: Option, } #[derive(Debug, Clone)] pub struct DiagnosticBundle { pub diagnostics: Vec, } impl DiagnosticBundle { pub fn new() -> Self { Self { diagnostics: Vec::new(), } } pub fn push(&mut self, diagnostic: Diagnostic) { self.diagnostics.push(diagnostic); } pub fn error(message: String, span: Option) -> Self { let mut bundle = Self::new(); bundle.push(Diagnostic { level: DiagnosticLevel::Error, code: None, message, span, }); bundle } pub fn has_errors(&self) -> bool { self.diagnostics .iter() .any(|d| matches!(d.level, DiagnosticLevel::Error)) } } impl From for DiagnosticBundle { fn from(diagnostic: Diagnostic) -> Self { let mut bundle = Self::new(); bundle.push(diagnostic); bundle } }