From f5ac3130001ab7fe64dd542fd866a18012ee9971 Mon Sep 17 00:00:00 2001 From: Timo Freiberg Date: Tue, 9 Jun 2020 23:11:16 +0200 Subject: Add quickfix to add a struct field --- crates/ra_hir_ty/src/diagnostics.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'crates/ra_hir_ty/src/diagnostics.rs') diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/ra_hir_ty/src/diagnostics.rs index 2c7298714..ebd9cb08f 100644 --- a/crates/ra_hir_ty/src/diagnostics.rs +++ b/crates/ra_hir_ty/src/diagnostics.rs @@ -6,7 +6,7 @@ use hir_expand::{db::AstDatabase, name::Name, HirFileId, InFile}; use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr}; use stdx::format_to; -pub use hir_def::{diagnostics::UnresolvedModule, expr::MatchArm}; +pub use hir_def::{diagnostics::UnresolvedModule, expr::MatchArm, path::Path}; pub use hir_expand::diagnostics::{AstDiagnostic, Diagnostic, DiagnosticSink}; #[derive(Debug)] @@ -29,6 +29,16 @@ impl Diagnostic for NoSuchField { } } +impl AstDiagnostic for NoSuchField { + type AST = ast::RecordField; + + fn ast(&self, db: &impl AstDatabase) -> Self::AST { + let root = db.parse_or_expand(self.source().file_id).unwrap(); + let node = self.source().value.to_node(&root); + ast::RecordField::cast(node).unwrap() + } +} + #[derive(Debug)] pub struct MissingFields { pub file: HirFileId, -- cgit v1.2.3