aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/diagnostics.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide/src/diagnostics.rs')
-rw-r--r--crates/ide/src/diagnostics.rs35
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
7mod diagnostics_with_fix; 7mod fixes;
8 8
9use std::cell::RefCell; 9use std::cell::RefCell;
10 10
@@ -19,9 +19,38 @@ use syntax::{
19}; 19};
20use text_edit::TextEdit; 20use text_edit::TextEdit;
21 21
22use crate::{Diagnostic, FileId, Fix, SourceFileEdit}; 22use crate::{FileId, SourceChange, SourceFileEdit};
23 23
24use self::diagnostics_with_fix::DiagnosticWithFix; 24use self::fixes::DiagnosticWithFix;
25
26#[derive(Debug)]
27pub 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)]
36pub 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
43impl 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)]
27pub enum Severity { 56pub enum Severity {