1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use super::{DiagnosticRelatedInformation, DiagnosticSeverity, Range};
use jsonrpc::Union;

/// Represents a diagnostic, such as a compiler error or warning. Diagnostic objects
/// are only valid in the scope of a resource.
#[derive(Debug, Serialize)]
pub struct Diagnostic {
    /// The range at which the message applies
    pub range: Range,

    /// The diagnostic's severity. Can be omitted. If omitted it is up to the
    /// client to interpret diagnostics as error, warning, info or hint.
    pub severity: Option<DiagnosticSeverity>,

    /// The diagnostic's code, which might appear in the user interface.
    pub code: Option<Union<i32, String>>,

    /// A human-readable string describing the source of this
    /// diagnostic, e.g. 'typescript' or 'super lint'.
    pub source: Option<String>,

    /// The diagnostic's message.
    pub message: String,

    /// An array of related diagnostic information, e.g. when symbol-names within
    /// a scope collide all definitions can be marked via this property.
    pub related_information: Option<Vec<DiagnosticRelatedInformation>>,
}

/// The Diagnostic namespace provides helper functions to work with
/// [Diagnostic](#Diagnostic) literals.
impl Diagnostic {
    /// Creates a new Diagnostic literal.
    pub fn create(
        range: Range,
        message: String,
        severity: Option<DiagnosticSeverity>,
        code: Option<Union<i32, String>>,
        source: Option<String>,
        related_information: Option<Vec<DiagnosticRelatedInformation>>,
    ) -> Self {
        Diagnostic {
            range,
            message,
            severity,
            code,
            source,
            related_information,
        }
    }
}