aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-07-05 17:43:23 +0100
committerbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-07-05 17:43:23 +0100
commita9dcd2cdca014d30e35638db4edeacbbf6eae6b3 (patch)
tree94bf1d637fe613360619b862f0d6126d478ec433 /crates/ra_hir/src
parent3775e5e27d39301770d396f320aac97b48cd47c0 (diff)
parent0b5e39919034d11c36655369f60cf9cc256743d0 (diff)
Merge #1495
1495: use correct file for diagnostics r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/diagnostics.rs18
1 files changed, 17 insertions, 1 deletions
diff --git a/crates/ra_hir/src/diagnostics.rs b/crates/ra_hir/src/diagnostics.rs
index f5f2e65f3..c97f0656d 100644
--- a/crates/ra_hir/src/diagnostics.rs
+++ b/crates/ra_hir/src/diagnostics.rs
@@ -1,6 +1,6 @@
1use std::{any::Any, fmt}; 1use std::{any::Any, fmt};
2 2
3use ra_syntax::{ast, AstPtr, SyntaxNode, SyntaxNodePtr, TextRange, TreeArc}; 3use ra_syntax::{ast, AstNode, AstPtr, SyntaxNode, SyntaxNodePtr, TextRange, TreeArc};
4use relative_path::RelativePathBuf; 4use relative_path::RelativePathBuf;
5 5
6use crate::{HirDatabase, HirFileId, Name}; 6use crate::{HirDatabase, HirFileId, Name};
@@ -27,11 +27,17 @@ pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static {
27 fn as_any(&self) -> &(dyn Any + Send + 'static); 27 fn as_any(&self) -> &(dyn Any + Send + 'static);
28} 28}
29 29
30pub trait AstDiagnostic {
31 type AST;
32 fn ast(&self, db: &impl HirDatabase) -> Self::AST;
33}
34
30impl dyn Diagnostic { 35impl dyn Diagnostic {
31 pub fn syntax_node(&self, db: &impl HirDatabase) -> TreeArc<SyntaxNode> { 36 pub fn syntax_node(&self, db: &impl HirDatabase) -> TreeArc<SyntaxNode> {
32 let node = db.parse_or_expand(self.file()).unwrap(); 37 let node = db.parse_or_expand(self.file()).unwrap();
33 self.syntax_node_ptr().to_node(&*node).to_owned() 38 self.syntax_node_ptr().to_node(&*node).to_owned()
34 } 39 }
40
35 pub fn downcast_ref<D: Diagnostic>(&self) -> Option<&D> { 41 pub fn downcast_ref<D: Diagnostic>(&self) -> Option<&D> {
36 self.as_any().downcast_ref() 42 self.as_any().downcast_ref()
37 } 43 }
@@ -135,3 +141,13 @@ impl Diagnostic for MissingFields {
135 self 141 self
136 } 142 }
137} 143}
144
145impl AstDiagnostic for MissingFields {
146 type AST = TreeArc<ast::NamedFieldList>;
147
148 fn ast(&self, db: &impl HirDatabase) -> Self::AST {
149 let root = db.parse_or_expand(self.file()).unwrap();
150 let node = self.syntax_node_ptr().to_node(&*root);
151 ast::NamedFieldList::cast(&node).unwrap().to_owned()
152 }
153}