1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#![allow(dead_code)]
use crate::{
    makepad_micro_serde::*,
    makepad_code_editor::text::{Length, Position},
};

// rust compiler output json structs
#[derive(Clone, DeJson, Debug, Default)]
pub struct RustcTarget {
    pub kind: Vec<String>,
    pub crate_types: Vec<String>,
    pub name: String,
    pub src_path: String,
    pub edition: String,
    pub doc: Option<bool>,
    pub doctest: bool,
    pub test: bool
}

#[derive(Clone, DeJson, Debug, Default)]
pub struct RustcText {
    pub text: String,
    pub highlight_start: usize,
    pub highlight_end: usize
}

#[derive(Clone, DeJson, Debug, Default)]
pub struct RustcSpan {
    pub file_name: String,
    pub byte_start: usize,
    pub byte_end: usize,
    pub line_start: usize,
    pub line_end: usize,
    pub column_start: usize,
    pub column_end: usize,
    pub is_primary: bool,
    pub text: Vec<RustcText>,
    pub label: Option<String>,
    pub suggested_replacement: Option<String>,
    pub suggestion_applicability: Option<String>,
    pub expansion: Option<Box<RustcExpansion >>,
    pub level: Option<String>
}

impl RustcSpan {
    pub fn start(&self) -> Position {
        Position {
            line_index: self.line_start - 1,
            byte_index: self.column_start - 1
        }
    }

    pub fn end(&self) -> Position {
        Position {
            line_index: self.line_end - 1,
            byte_index: self.column_end - 1
        }
    }

    pub fn length(&self) -> Length {
        self.end() - self.start()
    }
}

#[derive(Clone, DeJson, Debug, Default)]
pub struct RustcExpansion {
    pub span: Option<RustcSpan>,
    pub macro_decl_name: String,
    pub def_site_span: Option<RustcSpan>
}

#[derive(Clone, DeJson, Debug, Default)]
pub struct RustcCode {
    pub code: String,
    pub explanation: Option<String>
}

#[derive(Clone, DeJson, Debug, Default)]
pub struct RustcMessage {
    pub message: String,
    pub code: Option<RustcCode>,
    pub level: String,
    pub spans: Vec<RustcSpan>,
    pub children: Vec<RustcMessage>,
    pub rendered: Option<String>
}

#[derive(Clone, DeJson, Debug, Default)]
pub struct RustcProfile {
    pub opt_level: String,
    pub debuginfo: Option<usize>,
    pub debug_assertions: bool,
    pub overflow_checks: bool,
    pub test: bool
}

#[derive(Clone, DeJson, Debug, Default)]
pub struct RustcCompilerMessage {
    pub reason: String,
    pub signal: Option<u64>,
    pub success: Option<bool>,
    pub package_id: Option<String>,
    pub manifest_path: Option<String>,
    pub linked_libs: Option<Vec<String >>,
    pub linked_paths: Option<Vec<String >>,
    pub cfgs: Option<Vec<String >>,
    pub env: Option<Vec<String >>,
    pub target: Option<RustcTarget>,
    pub message: Option<RustcMessage>,
    pub profile: Option<RustcProfile>,
    pub out_dir: Option<String>,
    pub features: Option<Vec<String >>,
    pub filenames: Option<Vec<String >>,
    pub executable: Option<String>,
    pub fresh: Option<bool>
}