From ae609d7953297b355616c7862b8deefe74a8f95f Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Mon, 4 Nov 2019 01:44:23 +0800 Subject: Add parent_expansion to HirFileId --- crates/ra_hir_expand/src/lib.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index 194020b45..180cd1f57 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs @@ -20,6 +20,7 @@ use ra_syntax::{ }; use crate::ast_id_map::FileAstId; +use std::sync::Arc; /// Input to the analyzer is a set of files, where each file is identified by /// `FileId` and contains source code. However, another source of source code in @@ -66,6 +67,24 @@ impl HirFileId { } } } + + /// Return expansion information if it is a macro-expansion file + pub fn parent_expansion( + self, + db: &dyn db::AstDatabase, + ) -> Option<((HirFileId, HirFileId), Arc)> { + match self.0 { + HirFileIdRepr::FileId(_) => None, + HirFileIdRepr::MacroFile(macro_file) => { + let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id); + + let def_file = loc.def.ast_id.file_id; + let arg_file = loc.ast_id.file_id; + + db.macro_expansion_info(macro_file).map(|ex| ((arg_file, def_file), ex)) + } + } + } } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -- cgit v1.2.3