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

            
3
use crate::diagnostics::error_detection::semantic_errors::detect_semantic_errors;
4
use crate::diagnostics::error_detection::syntactic_errors::detect_syntactic_errors;
5

            
6
// structs for lsp stuff
7

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

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

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

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

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

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

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

            
72
    // semantic error detection from error-detection/semantic-errors.rs
73
    diagnostics.extend(detect_semantic_errors(source)); // not implemented yet
74

            
75
    // syntactic error detection from error-detection/syntactic-errors.rs
76
    diagnostics.extend(detect_syntactic_errors(source)); // not implemented yet
77

            
78
    diagnostics
79
}
80

            
81
// get document symbols for semantic highlighting