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
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
} // to be extended
53

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

            
67
// getting the actual diagnostic
68
385
pub fn get_diagnostics(source: &str) -> Vec<Diagnostic> {
69
385
    let mut diagnostics = Vec::new();
70

            
71
770
    diagnostics.extend(detect_errors(source));
72
385

            
73
385
    diagnostics
74
770
}
75

            
76
// get document symbols for semantic highlighting