diff options
Diffstat (limited to 'crates/ide/src')
-rw-r--r-- | crates/ide/src/diagnostics.rs | 35 | ||||
-rw-r--r-- | crates/ide/src/diagnostics/fixes.rs (renamed from crates/ide/src/diagnostics/diagnostics_with_fix.rs) | 10 | ||||
-rw-r--r-- | crates/ide/src/lib.rs | 31 |
3 files changed, 40 insertions, 36 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 { |
diff --git a/crates/ide/src/diagnostics/diagnostics_with_fix.rs b/crates/ide/src/diagnostics/fixes.rs index 85b46c995..68ae1c239 100644 --- a/crates/ide/src/diagnostics/diagnostics_with_fix.rs +++ b/crates/ide/src/diagnostics/fixes.rs | |||
@@ -1,7 +1,5 @@ | |||
1 | //! Provides a way to attach fixes to the diagnostics. | 1 | //! Provides a way to attach fixes to the diagnostics. |
2 | //! The same module also has all curret custom fixes for the diagnostics implemented. | 2 | //! The same module also has all curret custom fixes for the diagnostics implemented. |
3 | use crate::Fix; | ||
4 | use ast::{edit::IndentLevel, make}; | ||
5 | use base_db::FileId; | 3 | use base_db::FileId; |
6 | use hir::{ | 4 | use hir::{ |
7 | db::AstDatabase, | 5 | db::AstDatabase, |
@@ -12,9 +10,15 @@ use ide_db::{ | |||
12 | source_change::{FileSystemEdit, SourceFileEdit}, | 10 | source_change::{FileSystemEdit, SourceFileEdit}, |
13 | RootDatabase, | 11 | RootDatabase, |
14 | }; | 12 | }; |
15 | use syntax::{algo, ast, AstNode}; | 13 | use syntax::{ |
14 | algo, | ||
15 | ast::{self, edit::IndentLevel, make}, | ||
16 | AstNode, | ||
17 | }; | ||
16 | use text_edit::TextEdit; | 18 | use text_edit::TextEdit; |
17 | 19 | ||
20 | use crate::diagnostics::Fix; | ||
21 | |||
18 | /// A [Diagnostic] that potentially has a fix available. | 22 | /// A [Diagnostic] that potentially has a fix available. |
19 | /// | 23 | /// |
20 | /// [Diagnostic]: hir::diagnostics::Diagnostic | 24 | /// [Diagnostic]: hir::diagnostics::Diagnostic |
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index 2a73abba2..f37119e28 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs | |||
@@ -65,7 +65,7 @@ pub use crate::{ | |||
65 | completion::{ | 65 | completion::{ |
66 | CompletionConfig, CompletionItem, CompletionItemKind, CompletionScore, InsertTextFormat, | 66 | CompletionConfig, CompletionItem, CompletionItemKind, CompletionScore, InsertTextFormat, |
67 | }, | 67 | }, |
68 | diagnostics::{DiagnosticsConfig, Severity}, | 68 | diagnostics::{Diagnostic, DiagnosticsConfig, Fix, Severity}, |
69 | display::NavigationTarget, | 69 | display::NavigationTarget, |
70 | expand_macro::ExpandedMacro, | 70 | expand_macro::ExpandedMacro, |
71 | file_structure::StructureNode, | 71 | file_structure::StructureNode, |
@@ -99,35 +99,6 @@ pub use text_edit::{Indel, TextEdit}; | |||
99 | 99 | ||
100 | pub type Cancelable<T> = Result<T, Canceled>; | 100 | pub type Cancelable<T> = Result<T, Canceled>; |
101 | 101 | ||
102 | #[derive(Debug)] | ||
103 | pub struct Diagnostic { | ||
104 | pub name: Option<String>, | ||
105 | pub message: String, | ||
106 | pub range: TextRange, | ||
107 | pub severity: Severity, | ||
108 | pub fix: Option<Fix>, | ||
109 | } | ||
110 | |||
111 | #[derive(Debug)] | ||
112 | pub struct Fix { | ||
113 | pub label: String, | ||
114 | pub source_change: SourceChange, | ||
115 | /// Allows to trigger the fix only when the caret is in the range given | ||
116 | pub fix_trigger_range: TextRange, | ||
117 | } | ||
118 | |||
119 | impl Fix { | ||
120 | pub fn new( | ||
121 | label: impl Into<String>, | ||
122 | source_change: SourceChange, | ||
123 | fix_trigger_range: TextRange, | ||
124 | ) -> Self { | ||
125 | let label = label.into(); | ||
126 | assert!(label.starts_with(char::is_uppercase) && !label.ends_with('.')); | ||
127 | Self { label, source_change, fix_trigger_range } | ||
128 | } | ||
129 | } | ||
130 | |||
131 | /// Info associated with a text range. | 102 | /// Info associated with a text range. |
132 | #[derive(Debug)] | 103 | #[derive(Debug)] |
133 | pub struct RangeInfo<T> { | 104 | pub struct RangeInfo<T> { |