1
use serde::{Deserialize, Serialize};
2

            
3
use crate::diagnostics::error_detection::collect_errors::detect_errors;
4

            
5
// structs for lsp stuff
6

            
7
// position / range
8
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
9
#[serde(rename_all = "camelCase")]
10
pub struct Position {
11
    pub line: u32,
12
    pub character: u32,
13
}
14

            
15
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
16
#[serde(rename_all = "camelCase")]
17
pub struct Range {
18
    pub start: Position,
19
    pub end: Position,
20
}
21

            
22
// the actual values can be chnaged later, if needed
23
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
24
#[serde(rename_all = "camelCase")]
25
pub enum Severity {
26
    Error = 1,
27
    Warn = 2,
28
    Info = 3,
29
    Hint = 4,
30
}
31

            
32
// the actual diagnostic struct
33
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
34
#[serde(rename_all = "camelCase")]
35
pub struct Diagnostic {
36
    pub range: Range,
37
    pub severity: Severity,
38
    pub message: String,
39
    pub source: &'static str,
40
}
41

            
42
// document symbol struct is used to denote a single token / node
43
// this will be used for syntax highlighting and hovering
44
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
45
#[serde(rename_all = "camelCase")]
46
pub enum SymbolKind {
47
    Integer = 0,
48
    Decimal = 1,
49
    Function = 2,
50
    Letting = 3,
51
    Find = 4,
52
    Variable = 5,
53
    Constant = 6,
54
    Domain = 7,
55
} // to be extended
56

            
57
// each type of token / symbol in the essence grammar will be
58
// assigned an integer, which would be mapped to a colour
59
#[derive(Debug, Clone, Serialize, Deserialize)]
60
#[serde(rename_all = "camelCase")]
61
pub struct DocumentSymbol {
62
    pub name: String,
63
    pub detail: Option<String>,
64
    pub kind: SymbolKind,
65
    pub range: Range,
66
    #[serde(skip_serializing_if = "Option::is_none")]
67
    pub children: Option<Vec<DocumentSymbol>>,
68
}
69

            
70
// getting the actual diagnostic
71
1155
pub fn get_diagnostics(source: &str) -> Vec<Diagnostic> {
72
1155
    let mut diagnostics = Vec::new();
73

            
74
1155
    diagnostics.extend(detect_errors(source));
75

            
76
1155
    diagnostics
77
1155
}
78

            
79
// get document symbols for semantic highlighting