diff options
Diffstat (limited to 'crates/ide/src/diagnostics.rs')
-rw-r--r-- | crates/ide/src/diagnostics.rs | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs index 89ff55490..1f85805d2 100644 --- a/crates/ide/src/diagnostics.rs +++ b/crates/ide/src/diagnostics.rs | |||
@@ -4,7 +4,7 @@ | |||
4 | //! macro-expanded files, but we need to present them to the users in terms of | 4 | //! macro-expanded files, but we need to present them to the users in terms of |
5 | //! original files. So we need to map the ranges. | 5 | //! original files. So we need to map the ranges. |
6 | 6 | ||
7 | mod diagnostics_with_fix; | 7 | mod fixes; |
8 | 8 | ||
9 | use std::cell::RefCell; | 9 | use std::cell::RefCell; |
10 | 10 | ||
@@ -19,9 +19,38 @@ use syntax::{ | |||
19 | }; | 19 | }; |
20 | use text_edit::TextEdit; | 20 | use text_edit::TextEdit; |
21 | 21 | ||
22 | use crate::{Diagnostic, FileId, Fix, SourceFileEdit}; | 22 | use crate::{FileId, SourceChange, SourceFileEdit}; |
23 | 23 | ||
24 | use self::diagnostics_with_fix::DiagnosticWithFix; | 24 | use self::fixes::DiagnosticWithFix; |
25 | |||
26 | #[derive(Debug)] | ||
27 | pub struct Diagnostic { | ||
28 | pub name: Option<String>, | ||
29 | pub message: String, | ||
30 | pub range: TextRange, | ||
31 | pub severity: Severity, | ||
32 | pub fix: Option<Fix>, | ||
33 | } | ||
34 | |||
35 | #[derive(Debug)] | ||
36 | pub struct Fix { | ||
37 | pub label: String, | ||
38 | pub source_change: SourceChange, | ||
39 | /// Allows to trigger the fix only when the caret is in the range given | ||
40 | pub fix_trigger_range: TextRange, | ||
41 | } | ||
42 | |||
43 | impl Fix { | ||
44 | fn new( | ||
45 | label: impl Into<String>, | ||
46 | source_change: SourceChange, | ||
47 | fix_trigger_range: TextRange, | ||
48 | ) -> Self { | ||
49 | let label = label.into(); | ||
50 | assert!(label.starts_with(char::is_uppercase) && !label.ends_with('.')); | ||
51 | Self { label, source_change, fix_trigger_range } | ||
52 | } | ||
53 | } | ||
25 | 54 | ||
26 | #[derive(Debug, Copy, Clone)] | 55 | #[derive(Debug, Copy, Clone)] |
27 | pub enum Severity { | 56 | pub enum Severity { |