sdml_errors/diagnostics/mod.rs
1/*!
2Provides project-wide diagnostic types that describe more fine-grained error conditions..
3
4 */
5
6use crate::FileId;
7use codespan_reporting::diagnostic::Severity;
8use std::fmt::Display;
9
10// ------------------------------------------------------------------------------------------------
11// Public Types Diagnostics and Reporter
12// ------------------------------------------------------------------------------------------------
13
14///
15/// The type of structured diagnostic reports.
16///
17pub type Diagnostic = codespan_reporting::diagnostic::Diagnostic<FileId>;
18
19// ------------------------------------------------------------------------------------------------
20// Diagnostic Level
21// ------------------------------------------------------------------------------------------------
22
23///
24/// This value determines the level of diagnostics to be emitted by **any** reporter.
25///
26#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
27pub enum SeverityFilter {
28 Bug,
29 Error,
30 Warning,
31 Note,
32 Help,
33 None,
34}
35
36// ------------------------------------------------------------------------------------------------
37// Implementations
38// ------------------------------------------------------------------------------------------------
39
40impl Default for SeverityFilter {
41 fn default() -> Self {
42 Self::Error
43 }
44}
45
46impl Display for SeverityFilter {
47 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
48 write!(
49 f,
50 "{}",
51 match self {
52 Self::Bug => "=bugs",
53 Self::Error => ">=errors",
54 Self::Warning => ">=warnings",
55 Self::Note => ">=notes",
56 Self::Help => ">=help",
57 Self::None => "none",
58 }
59 )
60 }
61}
62
63impl From<Severity> for SeverityFilter {
64 fn from(value: Severity) -> Self {
65 match value {
66 Severity::Bug => Self::Bug,
67 Severity::Error => Self::Error,
68 Severity::Warning => Self::Warning,
69 Severity::Note => Self::Note,
70 Severity::Help => Self::Help,
71 }
72 }
73}
74
75// ------------------------------------------------------------------------------------------------
76// Modules
77// ------------------------------------------------------------------------------------------------
78
79pub mod codes;
80pub use codes::ErrorCode;
81
82pub mod color;
83pub use color::UseColor;
84
85pub mod functions;
86
87pub mod reporter;
88pub use reporter::{Reporter, StandardStreamReporter};