Improve composition diagnostics

This commit is contained in:
2026-06-22 17:37:51 +09:00
parent 8b3df21cfa
commit cc5ab63922
10 changed files with 518 additions and 175 deletions
+17 -1
View File
@@ -1,4 +1,4 @@
use alloc::string::String;
use alloc::{string::String, vec::Vec};
use crate::span::Span;
@@ -9,6 +9,13 @@ pub struct Diagnostic {
pub kind: DiagnosticKind,
pub span: Span,
pub message: String,
pub labels: Vec<DiagnosticLabel>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DiagnosticLabel {
pub span: Span,
pub message: String,
}
impl Diagnostic {
@@ -17,12 +24,21 @@ impl Diagnostic {
kind,
span,
message: message.into(),
labels: Vec::new(),
}
}
pub fn syntax(span: Span, message: impl Into<String>) -> Self {
Self::new(DiagnosticKind::Syntax, span, message)
}
pub fn with_label(mut self, span: Span, message: impl Into<String>) -> Self {
self.labels.push(DiagnosticLabel {
span,
message: message.into(),
});
self
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]