aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_expand
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_expand')
-rw-r--r--crates/ra_hir_expand/src/diagnostics.rs17
1 files changed, 3 insertions, 14 deletions
diff --git a/crates/ra_hir_expand/src/diagnostics.rs b/crates/ra_hir_expand/src/diagnostics.rs
index 90a3b87f9..2b74473ce 100644
--- a/crates/ra_hir_expand/src/diagnostics.rs
+++ b/crates/ra_hir_expand/src/diagnostics.rs
@@ -16,18 +16,13 @@
16 16
17use std::{any::Any, fmt}; 17use std::{any::Any, fmt};
18 18
19use ra_syntax::{SyntaxNode, SyntaxNodePtr}; 19use ra_syntax::SyntaxNodePtr;
20 20
21use crate::{db::AstDatabase, InFile}; 21use 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 /// A source to be used in highlighting and other visual representations 25 fn presentation(&self) -> InFile<SyntaxNodePtr>;
26 fn source(&self) -> InFile<SyntaxNodePtr>;
27 /// A source to be used during the fix application
28 fn fix_source(&self) -> InFile<SyntaxNodePtr> {
29 self.source()
30 }
31 fn as_any(&self) -> &(dyn Any + Send + 'static); 26 fn as_any(&self) -> &(dyn Any + Send + 'static);
32 fn is_experimental(&self) -> bool { 27 fn is_experimental(&self) -> bool {
33 false 28 false
@@ -36,16 +31,10 @@ pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static {
36 31
37pub trait AstDiagnostic { 32pub trait AstDiagnostic {
38 type AST; 33 type AST;
39 fn ast(&self, db: &dyn AstDatabase) -> Self::AST; 34 fn fix_source(&self, db: &dyn AstDatabase) -> Self::AST;
40} 35}
41 36
42impl dyn Diagnostic { 37impl dyn Diagnostic {
43 pub fn syntax_node(&self, db: &impl AstDatabase) -> SyntaxNode {
44 let source = self.source();
45 let node = db.parse_or_expand(source.file_id).unwrap();
46 source.value.to_node(&node)
47 }
48
49 pub fn downcast_ref<D: Diagnostic>(&self) -> Option<&D> { 38 pub fn downcast_ref<D: Diagnostic>(&self) -> Option<&D> {
50 self.as_any().downcast_ref() 39 self.as_any().downcast_ref()
51 } 40 }