From 3bb9efb6b70445076858ab72bebbbd7e31347307 Mon Sep 17 00:00:00 2001 From: Yilin Chen Date: Sun, 21 Mar 2021 23:02:01 +0800 Subject: use the included file as the source of expanded include macro Signed-off-by: Yilin Chen --- crates/hir_expand/src/lib.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'crates/hir_expand/src/lib.rs') diff --git a/crates/hir_expand/src/lib.rs b/crates/hir_expand/src/lib.rs index f49fd4fda..b8045fda9 100644 --- a/crates/hir_expand/src/lib.rs +++ b/crates/hir_expand/src/lib.rs @@ -84,7 +84,11 @@ impl HirFileId { } MacroCallId::EagerMacro(id) => { let loc = db.lookup_intern_eager_expansion(id); - loc.call.file_id + if let Some(included_file) = loc.included_file { + return included_file; + } else { + loc.call.file_id + } } }; file_id.original_file(db) @@ -188,6 +192,21 @@ impl HirFileId { } } } + + /// Return whether this file is an include macro + pub fn is_include_macro(&self, db: &dyn db::AstDatabase) -> bool { + match self.0 { + HirFileIdRepr::MacroFile(macro_file) => match macro_file.macro_call_id { + MacroCallId::EagerMacro(id) => { + let loc = db.lookup_intern_eager_expansion(id); + return loc.included_file.is_some(); + } + _ => {} + }, + _ => {} + } + false + } } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -315,6 +334,8 @@ pub struct EagerCallLoc { pub(crate) subtree: Arc, pub(crate) krate: CrateId, pub(crate) call: AstId, + // The included file ID of the include macro. + pub(crate) included_file: Option, } /// ExpansionInfo mainly describes how to map text range between src and expanded macro -- cgit v1.2.3