Lines
0 %
Functions
use serde::{Deserialize, Serialize};
use crate::diagnostics::error_detection::semantic_errors::detect_semantic_errors;
use crate::diagnostics::error_detection::syntactic_errors::detect_syntactic_errors;
// structs for lsp stuff
// position / range
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Position {
pub line: u32,
pub character: u32,
}
pub struct Range {
pub start: Position,
pub end: Position,
// the actual values can be chnaged later, if needed
pub enum Severity {
Error = 1,
Warn = 2,
Info = 3,
Hint = 4,
// the actual diagnostic struct
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Diagnostic {
pub range: Range,
pub severity: Severity,
pub message: String,
pub source: &'static str,
// document symbol struct is used to denote a single token / node
// this will be used for syntax highlighting
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum SymbolKind {
Integer = 0,
Decimal = 1,
Function = 2,
Letting = 3,
Find = 4,
} // to be extended
// each type of token / symbol in the essence grammar will be
// assigned an integer, which would be mapped to a colour
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DocumentSymbol {
pub name: String,
pub detail: Option<String>,
pub kind: SymbolKind,
#[serde(skip_serializing_if = "Option::is_none")]
pub children: Option<Vec<DocumentSymbol>>,
// getting the actual diagnostic
pub fn get_diagnostics(source: &str) -> Vec<Diagnostic> {
let mut diagnostics = Vec::new();
// semantic error detection from error-detection/semantic-errors.rs
diagnostics.extend(detect_semantic_errors(source)); // not implemented yet
// syntactic error detection from error-detection/syntactic-errors.rs
diagnostics.extend(detect_syntactic_errors(source)); // not implemented yet
diagnostics
// get document symbols for semantic highlighting