emmylua_code_analysis/config/configs/
diagnostics.rs

1use std::collections::HashMap;
2
3use lsp_types::DiagnosticSeverity;
4use schemars::JsonSchema;
5use serde::{Deserialize, Serialize};
6
7use crate::DiagnosticCode;
8
9#[derive(Serialize, Deserialize, Debug, JsonSchema, Clone)]
10#[serde(rename_all = "camelCase")]
11/// Represents the diagnostic configuration for Emmyrc.
12pub struct EmmyrcDiagnostic {
13    /// A list of diagnostic codes that are disabled.
14    #[serde(default)]
15    pub disable: Vec<DiagnosticCode>,
16    /// A flag indicating whether diagnostics are enabled.
17    #[serde(default = "default_true")]
18    pub enable: bool,
19    /// A list of global variables.
20    #[serde(default)]
21    pub globals: Vec<String>,
22    /// A list of regular expressions for global variables.
23    #[serde(default)]
24    pub globals_regex: Vec<String>,
25    /// A map of diagnostic codes to their severity settings.
26    #[serde(default)]
27    pub severity: HashMap<DiagnosticCode, DiagnosticSeveritySetting>,
28    /// A list of diagnostic codes that are enabled.
29    #[serde(default)]
30    pub enables: Vec<DiagnosticCode>,
31    /// Delay between opening/changing a file and scanning it for errors, in milliseconds.
32    #[schemars(extend("x-vscode-setting" = true))]
33    pub diagnostic_interval: Option<u64>,
34}
35
36impl Default for EmmyrcDiagnostic {
37    fn default() -> Self {
38        Self {
39            disable: Vec::new(),
40            enable: default_true(),
41            globals: Vec::new(),
42            globals_regex: Vec::new(),
43            severity: HashMap::new(),
44            enables: Vec::new(),
45            diagnostic_interval: Some(500),
46        }
47    }
48}
49
50fn default_true() -> bool {
51    true
52}
53
54#[derive(Serialize, Deserialize, Debug, JsonSchema, Clone, Copy)]
55#[serde(rename_all = "camelCase")]
56pub enum DiagnosticSeveritySetting {
57    /// Represents an error diagnostic severity.
58    Error,
59    /// Represents a warning diagnostic severity.
60    Warning,
61    /// Represents an information diagnostic severity.
62    Information,
63    /// Represents a hint diagnostic severity.
64    Hint,
65}
66
67impl From<DiagnosticSeveritySetting> for DiagnosticSeverity {
68    fn from(severity: DiagnosticSeveritySetting) -> Self {
69        match severity {
70            DiagnosticSeveritySetting::Error => DiagnosticSeverity::ERROR,
71            DiagnosticSeveritySetting::Warning => DiagnosticSeverity::WARNING,
72            DiagnosticSeveritySetting::Information => DiagnosticSeverity::INFORMATION,
73            DiagnosticSeveritySetting::Hint => DiagnosticSeverity::HINT,
74        }
75    }
76}