diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-07-05 17:43:23 +0100 |
---|---|---|
committer | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-07-05 17:43:23 +0100 |
commit | a9dcd2cdca014d30e35638db4edeacbbf6eae6b3 (patch) | |
tree | 94bf1d637fe613360619b862f0d6126d478ec433 /crates/ra_hir/src | |
parent | 3775e5e27d39301770d396f320aac97b48cd47c0 (diff) | |
parent | 0b5e39919034d11c36655369f60cf9cc256743d0 (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.rs | 18 |
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 @@ | |||
1 | use std::{any::Any, fmt}; | 1 | use std::{any::Any, fmt}; |
2 | 2 | ||
3 | use ra_syntax::{ast, AstPtr, SyntaxNode, SyntaxNodePtr, TextRange, TreeArc}; | 3 | use ra_syntax::{ast, AstNode, AstPtr, SyntaxNode, SyntaxNodePtr, TextRange, TreeArc}; |
4 | use relative_path::RelativePathBuf; | 4 | use relative_path::RelativePathBuf; |
5 | 5 | ||
6 | use crate::{HirDatabase, HirFileId, Name}; | 6 | use 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 | ||
30 | pub trait AstDiagnostic { | ||
31 | type AST; | ||
32 | fn ast(&self, db: &impl HirDatabase) -> Self::AST; | ||
33 | } | ||
34 | |||
30 | impl dyn Diagnostic { | 35 | impl 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 | |||
145 | impl 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 | } | ||