diff options
Diffstat (limited to 'crates/ra_hir_expand')
-rw-r--r-- | crates/ra_hir_expand/src/diagnostics.rs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/crates/ra_hir_expand/src/diagnostics.rs b/crates/ra_hir_expand/src/diagnostics.rs index 074a8c45e..23f28a7f7 100644 --- a/crates/ra_hir_expand/src/diagnostics.rs +++ b/crates/ra_hir_expand/src/diagnostics.rs | |||
@@ -16,7 +16,7 @@ | |||
16 | 16 | ||
17 | use std::{any::Any, fmt}; | 17 | use std::{any::Any, fmt}; |
18 | 18 | ||
19 | use ra_syntax::SyntaxNodePtr; | 19 | use ra_syntax::{SyntaxNode, SyntaxNodePtr}; |
20 | 20 | ||
21 | use crate::{db::AstDatabase, InFile}; | 21 | use crate::{db::AstDatabase, InFile}; |
22 | 22 | ||
@@ -38,6 +38,11 @@ pub trait AstDiagnostic { | |||
38 | } | 38 | } |
39 | 39 | ||
40 | impl dyn Diagnostic { | 40 | impl dyn Diagnostic { |
41 | pub fn syntax_node(&self, db: &impl AstDatabase) -> SyntaxNode { | ||
42 | let node = db.parse_or_expand(self.source().file_id).unwrap(); | ||
43 | self.source().value.to_node(&node) | ||
44 | } | ||
45 | |||
41 | pub fn downcast_ref<D: Diagnostic>(&self) -> Option<&D> { | 46 | pub fn downcast_ref<D: Diagnostic>(&self) -> Option<&D> { |
42 | self.as_any().downcast_ref() | 47 | self.as_any().downcast_ref() |
43 | } | 48 | } |