1pub use aegean::*;
2
3pub trait Diagnostic<S: crate::Span> {
4 fn to_report(&self) -> crate::Report<S>;
5 fn set_span(&mut self, new_span: &S);
6 fn get_span(&self) -> Option<S>;
7 fn get_message(&self) -> Option<String>;
8 fn get_labels(&self) -> Vec<S>;
9 fn get_helps(&self) -> Vec<String>;
10 fn get_notes(&self) -> Vec<String>;
11 fn build_report_config(&self) -> DiagnosticConfig<S>;
12}
13
14#[derive(Debug, Clone)]
15pub struct DiagnosticConfig<S: crate::Span> {
16 pub span: Option<S>,
17 pub labels: Vec<S>,
18 pub helps: Vec<String>,
19 pub notes: Vec<String>,
20 pub message: String,
21 pub stacktrace: Vec<crate::StackFrame<S>>,
22}
23
24impl<S: crate::Span> DiagnosticConfig<S> {
25 pub fn new(
26 span: Option<S>,
27 labels: Vec<S>,
28 helps: Vec<String>,
29 notes: Vec<String>,
30 message: String,
31 stacktrace: Vec<crate::StackFrame<S>>,
32 ) -> Self {
33 Self {
34 span,
35 labels,
36 helps,
37 notes,
38 message,
39 stacktrace,
40 }
41 }
42
43 pub fn span(mut self, new_span: Option<S>) -> Self {
44 self.span = new_span;
45 self
46 }
47
48 pub fn labels(mut self, new_labels: Vec<S>) -> Self {
49 self.labels.extend(new_labels);
50 self
51 }
52
53 pub fn helps(mut self, new_helps: Vec<String>) -> Self {
54 self.helps.extend(new_helps);
55 self
56 }
57
58 pub fn notes(mut self, new_notes: Vec<String>) -> Self {
59 self.notes.extend(new_notes);
60 self
61 }
62
63 pub fn message(mut self, new_message: String) -> Self {
64 self.message = new_message;
65 self
66 }
67
68 pub fn stacktrace(mut self, new_stacktrace: Vec<crate::StackFrame<S>>) -> Self {
69 self.stacktrace.extend(new_stacktrace);
70 self
71 }
72}
73
74type DiagnosticConfigFn<T, S> = fn(&T, DiagnosticConfig<S>) -> DiagnosticConfig<S>;
75
76pub trait HasDiagnosticHooks<S: crate::Span> {
77 fn hooks() -> &'static [DiagnosticConfigFn<Self, S>] {
78 &[]
79 }
80}