summaryrefslogtreecommitdiff
path: root/support/texlab/crates/diagnostics/src/types.rs
blob: 9cbbf8936f7a983b2dad77b04c0ae30bcf4fcf69 (plain)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use line_index::LineCol;
use rowan::TextRange;
use syntax::BuildError;
use url::Url;

#[derive(Debug, PartialEq, Eq, Clone)]
pub enum TexError {
    UnexpectedRCurly,
    ExpectingRCurly,
    MismatchedEnvironment,
    UnusedLabel,
    UndefinedLabel,
    UndefinedCitation,
    DuplicateLabel(Vec<(Url, TextRange)>),
}

#[derive(Debug, PartialEq, Eq, Clone)]
pub enum BibError {
    ExpectingLCurly,
    ExpectingKey,
    ExpectingRCurly,
    ExpectingEq,
    ExpectingFieldValue,
    UnusedEntry,
    DuplicateEntry(Vec<(Url, TextRange)>),
}

#[derive(Debug, PartialEq, Eq, Clone)]
pub struct ChktexError {
    pub start: LineCol,
    pub end: LineCol,
    pub message: String,
    pub severity: ChktexSeverity,
    pub code: String,
}

#[derive(Debug, PartialEq, Eq, Clone)]
pub enum ChktexSeverity {
    Error,
    Warning,
    Message,
}

#[derive(Debug, PartialEq, Eq, Clone)]
pub enum Diagnostic {
    Tex(TextRange, TexError),
    Bib(TextRange, BibError),
    Build(TextRange, BuildError),
    Chktex(ChktexError),
}

impl Diagnostic {
    pub fn message(&self) -> &str {
        match self {
            Diagnostic::Tex(_, error) => match error {
                TexError::UnexpectedRCurly => "Unexpected \"}\"",
                TexError::ExpectingRCurly => "Expecting a curly bracket: \"}\"",
                TexError::MismatchedEnvironment => "Mismatched environment",
                TexError::UnusedLabel => "Unused label",
                TexError::UndefinedLabel => "Undefined reference",
                TexError::UndefinedCitation => "Undefined reference",
                TexError::DuplicateLabel(_) => "Duplicate label",
            },
            Diagnostic::Bib(_, error) => match error {
                BibError::ExpectingLCurly => "Expecting a curly bracket: \"{\"",
                BibError::ExpectingKey => "Expecting a key",
                BibError::ExpectingRCurly => "Expecting a curly bracket: \"}\"",
                BibError::ExpectingEq => "Expecting an equality sign: \"=\"",
                BibError::ExpectingFieldValue => "Expecting a field value",
                BibError::UnusedEntry => "Unused entry",
                BibError::DuplicateEntry(_) => "Duplicate entry key",
            },
            Diagnostic::Build(_, error) => &error.message,
            Diagnostic::Chktex(error) => &error.message,
        }
    }
}