diff options
-rw-r--r-- | crates/ra_hir/src/semantics.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir_def/src/diagnostics.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/diagnostics.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/diagnostics.rs | 39 | ||||
-rw-r--r-- | crates/ra_ide/src/diagnostics.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/diagnostics/diagnostics_with_fix.rs | 3 |
6 files changed, 30 insertions, 28 deletions
diff --git a/crates/ra_hir/src/semantics.rs b/crates/ra_hir/src/semantics.rs index 2dfe69039..e3c417b41 100644 --- a/crates/ra_hir/src/semantics.rs +++ b/crates/ra_hir/src/semantics.rs | |||
@@ -138,8 +138,8 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> { | |||
138 | self.imp.original_range(node) | 138 | self.imp.original_range(node) |
139 | } | 139 | } |
140 | 140 | ||
141 | pub fn diagnostics_presentation_range(&self, diagnostics: &dyn Diagnostic) -> FileRange { | 141 | pub fn diagnostics_display_range(&self, diagnostics: &dyn Diagnostic) -> FileRange { |
142 | self.imp.diagnostics_presentation_range(diagnostics) | 142 | self.imp.diagnostics_display_range(diagnostics) |
143 | } | 143 | } |
144 | 144 | ||
145 | pub fn ancestors_with_macros(&self, node: SyntaxNode) -> impl Iterator<Item = SyntaxNode> + '_ { | 145 | pub fn ancestors_with_macros(&self, node: SyntaxNode) -> impl Iterator<Item = SyntaxNode> + '_ { |
@@ -369,8 +369,8 @@ impl<'db> SemanticsImpl<'db> { | |||
369 | original_range(self.db, node.as_ref()) | 369 | original_range(self.db, node.as_ref()) |
370 | } | 370 | } |
371 | 371 | ||
372 | fn diagnostics_presentation_range(&self, diagnostics: &dyn Diagnostic) -> FileRange { | 372 | fn diagnostics_display_range(&self, diagnostics: &dyn Diagnostic) -> FileRange { |
373 | let src = diagnostics.presentation(); | 373 | let src = diagnostics.display_source(); |
374 | let root = self.db.parse_or_expand(src.file_id).unwrap(); | 374 | let root = self.db.parse_or_expand(src.file_id).unwrap(); |
375 | let node = src.value.to_node(&root); | 375 | let node = src.value.to_node(&root); |
376 | self.cache(root, src.file_id); | 376 | self.cache(root, src.file_id); |
diff --git a/crates/ra_hir_def/src/diagnostics.rs b/crates/ra_hir_def/src/diagnostics.rs index 9435c7254..71d177070 100644 --- a/crates/ra_hir_def/src/diagnostics.rs +++ b/crates/ra_hir_def/src/diagnostics.rs | |||
@@ -18,7 +18,7 @@ impl Diagnostic for UnresolvedModule { | |||
18 | fn message(&self) -> String { | 18 | fn message(&self) -> String { |
19 | "unresolved module".to_string() | 19 | "unresolved module".to_string() |
20 | } | 20 | } |
21 | fn presentation(&self) -> InFile<SyntaxNodePtr> { | 21 | fn display_source(&self) -> InFile<SyntaxNodePtr> { |
22 | InFile::new(self.file, self.decl.clone().into()) | 22 | InFile::new(self.file, self.decl.clone().into()) |
23 | } | 23 | } |
24 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | 24 | fn as_any(&self) -> &(dyn Any + Send + 'static) { |
diff --git a/crates/ra_hir_expand/src/diagnostics.rs b/crates/ra_hir_expand/src/diagnostics.rs index cc7dc3af2..b138500e7 100644 --- a/crates/ra_hir_expand/src/diagnostics.rs +++ b/crates/ra_hir_expand/src/diagnostics.rs | |||
@@ -22,8 +22,8 @@ use crate::InFile; | |||
22 | 22 | ||
23 | pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static { | 23 | pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static { |
24 | fn message(&self) -> String; | 24 | fn message(&self) -> String; |
25 | /// A presentation source of the diagnostics, to use in highlighting and similar actions | 25 | /// Used in highlighting and related purposes |
26 | fn presentation(&self) -> InFile<SyntaxNodePtr>; | 26 | fn display_source(&self) -> InFile<SyntaxNodePtr>; |
27 | fn as_any(&self) -> &(dyn Any + Send + 'static); | 27 | fn as_any(&self) -> &(dyn Any + Send + 'static); |
28 | fn is_experimental(&self) -> bool { | 28 | fn is_experimental(&self) -> bool { |
29 | false | 29 | false |
diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/ra_hir_ty/src/diagnostics.rs index 24435e8a7..7ab7f79db 100644 --- a/crates/ra_hir_ty/src/diagnostics.rs +++ b/crates/ra_hir_ty/src/diagnostics.rs | |||
@@ -37,7 +37,7 @@ impl Diagnostic for NoSuchField { | |||
37 | "no such field".to_string() | 37 | "no such field".to_string() |
38 | } | 38 | } |
39 | 39 | ||
40 | fn presentation(&self) -> InFile<SyntaxNodePtr> { | 40 | fn display_source(&self) -> InFile<SyntaxNodePtr> { |
41 | InFile::new(self.file, self.field.clone().into()) | 41 | InFile::new(self.file, self.field.clone().into()) |
42 | } | 42 | } |
43 | 43 | ||
@@ -63,7 +63,7 @@ impl Diagnostic for MissingFields { | |||
63 | buf | 63 | buf |
64 | } | 64 | } |
65 | 65 | ||
66 | fn presentation(&self) -> InFile<SyntaxNodePtr> { | 66 | fn display_source(&self) -> InFile<SyntaxNodePtr> { |
67 | InFile { | 67 | InFile { |
68 | file_id: self.file, | 68 | file_id: self.file, |
69 | value: self | 69 | value: self |
@@ -95,13 +95,15 @@ impl Diagnostic for MissingPatFields { | |||
95 | } | 95 | } |
96 | buf | 96 | buf |
97 | } | 97 | } |
98 | fn presentation(&self) -> InFile<SyntaxNodePtr> { | 98 | fn display_source(&self) -> InFile<SyntaxNodePtr> { |
99 | let value = self | 99 | InFile { |
100 | .field_list_parent_path | 100 | file_id: self.file, |
101 | .clone() | 101 | value: self |
102 | .map(SyntaxNodePtr::from) | 102 | .field_list_parent_path |
103 | .unwrap_or_else(|| self.field_list_parent.clone().into()); | 103 | .clone() |
104 | InFile { file_id: self.file, value } | 104 | .map(SyntaxNodePtr::from) |
105 | .unwrap_or_else(|| self.field_list_parent.clone().into()), | ||
106 | } | ||
105 | } | 107 | } |
106 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | 108 | fn as_any(&self) -> &(dyn Any + Send + 'static) { |
107 | self | 109 | self |
@@ -119,7 +121,7 @@ impl Diagnostic for MissingMatchArms { | |||
119 | fn message(&self) -> String { | 121 | fn message(&self) -> String { |
120 | String::from("Missing match arm") | 122 | String::from("Missing match arm") |
121 | } | 123 | } |
122 | fn presentation(&self) -> InFile<SyntaxNodePtr> { | 124 | fn display_source(&self) -> InFile<SyntaxNodePtr> { |
123 | InFile { file_id: self.file, value: self.match_expr.clone().into() } | 125 | InFile { file_id: self.file, value: self.match_expr.clone().into() } |
124 | } | 126 | } |
125 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | 127 | fn as_any(&self) -> &(dyn Any + Send + 'static) { |
@@ -137,7 +139,7 @@ impl Diagnostic for MissingOkInTailExpr { | |||
137 | fn message(&self) -> String { | 139 | fn message(&self) -> String { |
138 | "wrap return expression in Ok".to_string() | 140 | "wrap return expression in Ok".to_string() |
139 | } | 141 | } |
140 | fn presentation(&self) -> InFile<SyntaxNodePtr> { | 142 | fn display_source(&self) -> InFile<SyntaxNodePtr> { |
141 | InFile { file_id: self.file, value: self.expr.clone().into() } | 143 | InFile { file_id: self.file, value: self.expr.clone().into() } |
142 | } | 144 | } |
143 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | 145 | fn as_any(&self) -> &(dyn Any + Send + 'static) { |
@@ -155,7 +157,7 @@ impl Diagnostic for BreakOutsideOfLoop { | |||
155 | fn message(&self) -> String { | 157 | fn message(&self) -> String { |
156 | "break outside of loop".to_string() | 158 | "break outside of loop".to_string() |
157 | } | 159 | } |
158 | fn presentation(&self) -> InFile<SyntaxNodePtr> { | 160 | fn display_source(&self) -> InFile<SyntaxNodePtr> { |
159 | InFile { file_id: self.file, value: self.expr.clone().into() } | 161 | InFile { file_id: self.file, value: self.expr.clone().into() } |
160 | } | 162 | } |
161 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | 163 | fn as_any(&self) -> &(dyn Any + Send + 'static) { |
@@ -173,7 +175,7 @@ impl Diagnostic for MissingUnsafe { | |||
173 | fn message(&self) -> String { | 175 | fn message(&self) -> String { |
174 | format!("This operation is unsafe and requires an unsafe function or block") | 176 | format!("This operation is unsafe and requires an unsafe function or block") |
175 | } | 177 | } |
176 | fn presentation(&self) -> InFile<SyntaxNodePtr> { | 178 | fn display_source(&self) -> InFile<SyntaxNodePtr> { |
177 | InFile { file_id: self.file, value: self.expr.clone().into() } | 179 | InFile { file_id: self.file, value: self.expr.clone().into() } |
178 | } | 180 | } |
179 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | 181 | fn as_any(&self) -> &(dyn Any + Send + 'static) { |
@@ -194,7 +196,7 @@ impl Diagnostic for MismatchedArgCount { | |||
194 | let s = if self.expected == 1 { "" } else { "s" }; | 196 | let s = if self.expected == 1 { "" } else { "s" }; |
195 | format!("Expected {} argument{}, found {}", self.expected, s, self.found) | 197 | format!("Expected {} argument{}, found {}", self.expected, s, self.found) |
196 | } | 198 | } |
197 | fn presentation(&self) -> InFile<SyntaxNodePtr> { | 199 | fn display_source(&self) -> InFile<SyntaxNodePtr> { |
198 | InFile { file_id: self.file, value: self.call_expr.clone().into() } | 200 | InFile { file_id: self.file, value: self.call_expr.clone().into() } |
199 | } | 201 | } |
200 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | 202 | fn as_any(&self) -> &(dyn Any + Send + 'static) { |
@@ -256,12 +258,11 @@ mod tests { | |||
256 | 258 | ||
257 | let mut actual: FxHashMap<FileId, Vec<(TextRange, String)>> = FxHashMap::default(); | 259 | let mut actual: FxHashMap<FileId, Vec<(TextRange, String)>> = FxHashMap::default(); |
258 | db.diagnostics(|d| { | 260 | db.diagnostics(|d| { |
261 | let src = d.display_source(); | ||
262 | let root = db.parse_or_expand(src.file_id).unwrap(); | ||
259 | // FIXME: macros... | 263 | // FIXME: macros... |
260 | let diagnostics_presentation = d.presentation(); | 264 | let file_id = src.file_id.original_file(&db); |
261 | let root = db.parse_or_expand(diagnostics_presentation.file_id).unwrap(); | 265 | let range = src.value.to_node(&root).text_range(); |
262 | |||
263 | let file_id = diagnostics_presentation.file_id.original_file(&db); | ||
264 | let range = diagnostics_presentation.value.to_node(&root).text_range(); | ||
265 | let message = d.message().to_owned(); | 266 | let message = d.message().to_owned(); |
266 | actual.entry(file_id).or_default().push((range, message)); | 267 | actual.entry(file_id).or_default().push((range, message)); |
267 | }); | 268 | }); |
diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs index 757b76fd4..1046d7ab3 100644 --- a/crates/ra_ide/src/diagnostics.rs +++ b/crates/ra_ide/src/diagnostics.rs | |||
@@ -183,7 +183,7 @@ mod tests { | |||
183 | /// Takes a multi-file input fixture with annotated cursor positions, | 183 | /// Takes a multi-file input fixture with annotated cursor positions, |
184 | /// and checks that: | 184 | /// and checks that: |
185 | /// * a diagnostic is produced | 185 | /// * a diagnostic is produced |
186 | /// * this diagnostic fix touches the input cursor position | 186 | /// * this diagnostic fix trigger range touches the input cursor position |
187 | /// * that the contents of the file containing the cursor match `after` after the diagnostic fix is applied | 187 | /// * that the contents of the file containing the cursor match `after` after the diagnostic fix is applied |
188 | fn check_fix(ra_fixture_before: &str, ra_fixture_after: &str) { | 188 | fn check_fix(ra_fixture_before: &str, ra_fixture_after: &str) { |
189 | let after = trim_indent(ra_fixture_after); | 189 | let after = trim_indent(ra_fixture_after); |
diff --git a/crates/ra_ide/src/diagnostics/diagnostics_with_fix.rs b/crates/ra_ide/src/diagnostics/diagnostics_with_fix.rs index 57b54a61e..f7c73773f 100644 --- a/crates/ra_ide/src/diagnostics/diagnostics_with_fix.rs +++ b/crates/ra_ide/src/diagnostics/diagnostics_with_fix.rs | |||
@@ -1,4 +1,5 @@ | |||
1 | //! Provides a way to attach fix actions to the | 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 | use crate::Fix; | 3 | use crate::Fix; |
3 | use ast::{edit::IndentLevel, make}; | 4 | use ast::{edit::IndentLevel, make}; |
4 | use hir::{ | 5 | use hir::{ |