rune/workspace/
diagnostics.rsuse crate::alloc::{self, Vec};
use crate::workspace::WorkspaceError;
use crate::SourceId;
#[derive(Debug)]
pub struct FatalDiagnostic {
source_id: SourceId,
error: WorkspaceError,
}
impl FatalDiagnostic {
pub fn source_id(&self) -> SourceId {
self.source_id
}
pub fn error(&self) -> &WorkspaceError {
&self.error
}
}
#[derive(Debug)]
#[non_exhaustive]
pub enum Diagnostic {
Fatal(FatalDiagnostic),
}
#[derive(Default)]
pub struct Diagnostics {
pub(crate) diagnostics: Vec<Diagnostic>,
}
impl Diagnostics {
pub fn diagnostics(&self) -> &[Diagnostic] {
&self.diagnostics
}
pub fn has_errors(&self) -> bool {
self.diagnostics
.iter()
.any(|e| matches!(e, Diagnostic::Fatal(..)))
}
pub fn is_empty(&self) -> bool {
self.diagnostics.is_empty()
}
pub(crate) fn fatal(
&mut self,
source_id: SourceId,
error: WorkspaceError,
) -> alloc::Result<()> {
self.diagnostics
.try_push(Diagnostic::Fatal(FatalDiagnostic { source_id, error }))
}
}
impl Diagnostics {
pub fn new() -> Self {
Self::default()
}
}