expand to syntax node

This commit is contained in:
Aleksey Kladov 2019-05-14 01:42:59 +03:00
parent 101b3abfd7
commit 16c7405262
6 changed files with 33 additions and 26 deletions

View file

@ -1,6 +1,6 @@
use std::{fmt, any::Any};
use ra_syntax::{SyntaxNodePtr, TreeArc, AstPtr, TextRange, ast, SyntaxNode, AstNode};
use ra_syntax::{SyntaxNodePtr, TreeArc, AstPtr, TextRange, ast, SyntaxNode};
use relative_path::RelativePathBuf;
use crate::{HirFileId, HirDatabase, Name};
@ -29,8 +29,8 @@ pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static {
impl dyn Diagnostic {
pub fn syntax_node(&self, db: &impl HirDatabase) -> TreeArc<SyntaxNode> {
let source_file = db.hir_parse(self.file());
self.syntax_node_ptr().to_node(source_file.syntax()).to_owned()
let node = db.parse_or_expand(self.file()).unwrap();
self.syntax_node_ptr().to_node(&*node).to_owned()
}
pub fn downcast_ref<D: Diagnostic>(&self) -> Option<&D> {
self.as_any().downcast_ref()