// Copyright © 2024-2025 The µcad authors <info@ucad.xyz>
// SPDX-License-Identifier: AGPL-3.0-or-later

use crate::{diag::*, resolve::*};
use derive_more::{Deref, DerefMut};

/// Source file diagnostics.
#[derive(Debug, Default, Deref, DerefMut)]
pub struct DiagList(Vec<Diagnostic>);

impl DiagList {
    /// Pretty print this list of diagnostics.
    pub fn pretty_print(
        &self,
        f: &mut dyn std::fmt::Write,
        source_by_hash: &impl GetSourceByHash,
        line_offset: usize,
    ) -> std::fmt::Result {
        self.0
            .iter()
            .try_for_each(|diag| diag.pretty_print(f, source_by_hash, line_offset))
    }
}

impl PushDiag for DiagList {
    fn push_diag(&mut self, diag: Diagnostic) -> DiagResult<()> {
        self.0.push(diag);
        Ok(())
    }
}
