From 0b5e39919034d11c36655369f60cf9cc256743d0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 5 Jul 2019 19:40:02 +0300 Subject: use correct file for diagnostics closes #1475 --- crates/ra_hir/src/diagnostics.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'crates/ra_hir/src/diagnostics.rs') 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 @@ use std::{any::Any, fmt}; -use ra_syntax::{ast, AstPtr, SyntaxNode, SyntaxNodePtr, TextRange, TreeArc}; +use ra_syntax::{ast, AstNode, AstPtr, SyntaxNode, SyntaxNodePtr, TextRange, TreeArc}; use relative_path::RelativePathBuf; use crate::{HirDatabase, HirFileId, Name}; @@ -27,11 +27,17 @@ pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static { fn as_any(&self) -> &(dyn Any + Send + 'static); } +pub trait AstDiagnostic { + type AST; + fn ast(&self, db: &impl HirDatabase) -> Self::AST; +} + impl dyn Diagnostic { pub fn syntax_node(&self, db: &impl HirDatabase) -> TreeArc { let node = db.parse_or_expand(self.file()).unwrap(); self.syntax_node_ptr().to_node(&*node).to_owned() } + pub fn downcast_ref(&self) -> Option<&D> { self.as_any().downcast_ref() } @@ -135,3 +141,13 @@ impl Diagnostic for MissingFields { self } } + +impl AstDiagnostic for MissingFields { + type AST = TreeArc; + + fn ast(&self, db: &impl HirDatabase) -> Self::AST { + let root = db.parse_or_expand(self.file()).unwrap(); + let node = self.syntax_node_ptr().to_node(&*root); + ast::NamedFieldList::cast(&node).unwrap().to_owned() + } +} -- cgit v1.2.3