aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir_def/src/diagnostics.rs2
-rw-r--r--crates/ra_hir_expand/src/diagnostics.rs13
-rw-r--r--crates/ra_hir_ty/src/diagnostics.rs12
3 files changed, 15 insertions, 12 deletions
diff --git a/crates/ra_hir_def/src/diagnostics.rs b/crates/ra_hir_def/src/diagnostics.rs
index e53269589..30db48f86 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 fix_source(&self) -> InFile<SyntaxNodePtr> { 21 fn 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 23f28a7f7..90a3b87f9 100644
--- a/crates/ra_hir_expand/src/diagnostics.rs
+++ b/crates/ra_hir_expand/src/diagnostics.rs
@@ -22,9 +22,11 @@ use crate::{db::AstDatabase, InFile};
22 22
23pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static { 23pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static {
24 fn message(&self) -> String; 24 fn message(&self) -> String;
25 fn fix_source(&self) -> InFile<SyntaxNodePtr>; 25 /// A source to be used in highlighting and other visual representations
26 fn source(&self) -> InFile<SyntaxNodePtr> { 26 fn source(&self) -> InFile<SyntaxNodePtr>;
27 self.fix_source() 27 /// A source to be used during the fix application
28 fn fix_source(&self) -> InFile<SyntaxNodePtr> {
29 self.source()
28 } 30 }
29 fn as_any(&self) -> &(dyn Any + Send + 'static); 31 fn as_any(&self) -> &(dyn Any + Send + 'static);
30 fn is_experimental(&self) -> bool { 32 fn is_experimental(&self) -> bool {
@@ -39,8 +41,9 @@ pub trait AstDiagnostic {
39 41
40impl dyn Diagnostic { 42impl dyn Diagnostic {
41 pub fn syntax_node(&self, db: &impl AstDatabase) -> SyntaxNode { 43 pub fn syntax_node(&self, db: &impl AstDatabase) -> SyntaxNode {
42 let node = db.parse_or_expand(self.source().file_id).unwrap(); 44 let source = self.source();
43 self.source().value.to_node(&node) 45 let node = db.parse_or_expand(source.file_id).unwrap();
46 source.value.to_node(&node)
44 } 47 }
45 48
46 pub fn downcast_ref<D: Diagnostic>(&self) -> Option<&D> { 49 pub fn downcast_ref<D: Diagnostic>(&self) -> Option<&D> {
diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/ra_hir_ty/src/diagnostics.rs
index 9d29f3071..efca09619 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 fix_source(&self) -> InFile<SyntaxNodePtr> { 40 fn 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
@@ -137,7 +137,7 @@ impl Diagnostic for MissingMatchArms {
137 fn message(&self) -> String { 137 fn message(&self) -> String {
138 String::from("Missing match arm") 138 String::from("Missing match arm")
139 } 139 }
140 fn fix_source(&self) -> InFile<SyntaxNodePtr> { 140 fn source(&self) -> InFile<SyntaxNodePtr> {
141 InFile { file_id: self.file, value: self.match_expr.clone().into() } 141 InFile { file_id: self.file, value: self.match_expr.clone().into() }
142 } 142 }
143 fn as_any(&self) -> &(dyn Any + Send + 'static) { 143 fn as_any(&self) -> &(dyn Any + Send + 'static) {
@@ -155,7 +155,7 @@ impl Diagnostic for MissingOkInTailExpr {
155 fn message(&self) -> String { 155 fn message(&self) -> String {
156 "wrap return expression in Ok".to_string() 156 "wrap return expression in Ok".to_string()
157 } 157 }
158 fn fix_source(&self) -> InFile<SyntaxNodePtr> { 158 fn source(&self) -> InFile<SyntaxNodePtr> {
159 InFile { file_id: self.file, value: self.expr.clone().into() } 159 InFile { file_id: self.file, value: self.expr.clone().into() }
160 } 160 }
161 fn as_any(&self) -> &(dyn Any + Send + 'static) { 161 fn as_any(&self) -> &(dyn Any + Send + 'static) {
@@ -182,7 +182,7 @@ impl Diagnostic for BreakOutsideOfLoop {
182 fn message(&self) -> String { 182 fn message(&self) -> String {
183 "break outside of loop".to_string() 183 "break outside of loop".to_string()
184 } 184 }
185 fn fix_source(&self) -> InFile<SyntaxNodePtr> { 185 fn source(&self) -> InFile<SyntaxNodePtr> {
186 InFile { file_id: self.file, value: self.expr.clone().into() } 186 InFile { file_id: self.file, value: self.expr.clone().into() }
187 } 187 }
188 fn as_any(&self) -> &(dyn Any + Send + 'static) { 188 fn as_any(&self) -> &(dyn Any + Send + 'static) {
@@ -209,7 +209,7 @@ impl Diagnostic for MissingUnsafe {
209 fn message(&self) -> String { 209 fn message(&self) -> String {
210 format!("This operation is unsafe and requires an unsafe function or block") 210 format!("This operation is unsafe and requires an unsafe function or block")
211 } 211 }
212 fn fix_source(&self) -> InFile<SyntaxNodePtr> { 212 fn source(&self) -> InFile<SyntaxNodePtr> {
213 InFile { file_id: self.file, value: self.expr.clone().into() } 213 InFile { file_id: self.file, value: self.expr.clone().into() }
214 } 214 }
215 fn as_any(&self) -> &(dyn Any + Send + 'static) { 215 fn as_any(&self) -> &(dyn Any + Send + 'static) {
@@ -239,7 +239,7 @@ impl Diagnostic for MismatchedArgCount {
239 let s = if self.expected == 1 { "" } else { "s" }; 239 let s = if self.expected == 1 { "" } else { "s" };
240 format!("Expected {} argument{}, found {}", self.expected, s, self.found) 240 format!("Expected {} argument{}, found {}", self.expected, s, self.found)
241 } 241 }
242 fn fix_source(&self) -> InFile<SyntaxNodePtr> { 242 fn source(&self) -> InFile<SyntaxNodePtr> {
243 InFile { file_id: self.file, value: self.call_expr.clone().into() } 243 InFile { file_id: self.file, value: self.call_expr.clone().into() }
244 } 244 }
245 fn as_any(&self) -> &(dyn Any + Send + 'static) { 245 fn as_any(&self) -> &(dyn Any + Send + 'static) {