summaryrefslogtreecommitdiff
path: root/support/texlab/crates/diagnostics/src/types.rs
diff options
context:
space:
mode:
Diffstat (limited to 'support/texlab/crates/diagnostics/src/types.rs')
-rw-r--r--support/texlab/crates/diagnostics/src/types.rs65
1 files changed, 52 insertions, 13 deletions
diff --git a/support/texlab/crates/diagnostics/src/types.rs b/support/texlab/crates/diagnostics/src/types.rs
index a443245b6f..9cbbf8936f 100644
--- a/support/texlab/crates/diagnostics/src/types.rs
+++ b/support/texlab/crates/diagnostics/src/types.rs
@@ -1,21 +1,9 @@
+use line_index::LineCol;
use rowan::TextRange;
use syntax::BuildError;
use url::Url;
#[derive(Debug, PartialEq, Eq, Clone)]
-pub struct Diagnostic {
- pub range: TextRange,
- pub data: DiagnosticData,
-}
-
-#[derive(Debug, PartialEq, Eq, Clone)]
-pub enum DiagnosticData {
- Tex(TexError),
- Bib(BibError),
- Build(BuildError),
-}
-
-#[derive(Debug, PartialEq, Eq, Clone)]
pub enum TexError {
UnexpectedRCurly,
ExpectingRCurly,
@@ -36,3 +24,54 @@ pub enum BibError {
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,
+ }
+ }
+}