1use crate::span::Span;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4pub enum Severity {
5 Error,
6 Warning,
7}
8
9#[derive(Debug, Clone, PartialEq)]
11pub struct Diagnostic {
12 pub code: &'static str,
13 pub severity: Severity,
14 pub message: String,
15 pub primary: (Span, String),
16 pub secondary: Vec<(Span, String)>,
17 pub help: Option<String>,
18}
19
20impl Diagnostic {
21 pub fn warning(
22 code: &'static str,
23 message: impl Into<String>,
24 span: Span,
25 label: impl Into<String>,
26 ) -> Self {
27 Diagnostic {
28 severity: Severity::Warning,
29 ..Self::error(code, message, span, label)
30 }
31 }
32
33 pub fn error(
34 code: &'static str,
35 message: impl Into<String>,
36 span: Span,
37 label: impl Into<String>,
38 ) -> Self {
39 Diagnostic {
40 code,
41 severity: Severity::Error,
42 message: message.into(),
43 primary: (span, label.into()),
44 secondary: Vec::new(),
45 help: None,
46 }
47 }
48}