kind_report/
data.rs

1use std::{time::Duration, path::PathBuf};
2
3use kind_span::{Range, SyntaxCtxIndex};
4
5use crate::RenderConfig;
6
7#[derive(Debug, Clone, PartialEq, Eq)]
8pub enum Severity {
9    Error,
10    Warning,
11    Info,
12}
13
14#[derive(Debug, Clone)]
15pub enum Color {
16    Fst,
17    Snd,
18    Thr,
19    For,
20    Fft,
21}
22
23#[derive(Debug, Clone)]
24pub enum Word {
25    Dimmed(String),
26    White(String),
27    Normal(String),
28    Painted(Color, String),
29}
30
31#[derive(Debug, Clone)]
32pub enum Subtitle {
33    Field(Color, String),
34    Normal(Color, String),
35    Bold(Color, String),
36    Phrase(Color, Vec<Word>),
37    LineBreak,
38}
39
40#[derive(Debug, Clone)]
41pub struct Marker {
42    pub position: Range,
43    pub color: Color,
44    pub text: String,
45    pub no_code: bool,
46    pub main: bool,
47}
48
49#[derive(Debug, Clone)]
50pub struct DiagnosticFrame {
51    pub code: u32,
52    pub severity: Severity,
53    pub title: String,
54    pub subtitles: Vec<Subtitle>,
55    pub hints: Vec<String>,
56    pub positions: Vec<Marker>,
57}
58
59pub struct Hints<'a>(pub &'a Vec<String>);
60
61pub struct Subtitles<'a>(pub &'a Vec<Subtitle>);
62
63pub struct Markers<'a>(pub &'a Vec<Marker>);
64
65pub struct Header<'a> {
66    pub severity: &'a Severity,
67    pub title: &'a String
68}
69
70pub enum Log {
71    Checking(String),
72    Checked(Duration),
73    Compiled(Duration),
74    Rewrites(u64),
75    Failed(Duration, u64, u64),
76    Empty,
77}
78
79pub trait Diagnostic {
80    fn get_syntax_ctx(&self) -> Option<SyntaxCtxIndex>;
81    fn get_severity(&self) -> Severity;
82    fn to_diagnostic_frame(&self, config: &RenderConfig) -> DiagnosticFrame;
83}
84
85pub trait FileCache {
86    fn fetch(&self, ctx: SyntaxCtxIndex) -> Option<(PathBuf, &String)>;
87}
88
89impl DiagnosticFrame {
90    pub fn subtitles(&self) -> Subtitles {
91        Subtitles(&self.subtitles)
92    }
93
94    pub fn hints(&self) -> Hints {
95        Hints(&self.hints)
96    }
97
98    pub fn header(&self) -> Header {
99        Header {
100            severity: &self.severity,
101            title: &self.title
102        }
103    }
104
105    pub fn markers(&self) -> Markers {
106        Markers(&self.positions)
107    }
108}