@@ -136,7 +136,7 @@ pub enum MacroDefKind {
136136}
137137
138138#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
139- struct EagerCallInfo {
139+ pub struct EagerCallInfo {
140140 /// The expanded argument of the eager macro.
141141 arg : Arc < tt:: Subtree > ,
142142 /// Call id of the eager macro's input file (this is the macro file for its fully expanded input).
@@ -176,6 +176,8 @@ pub trait HirFileIdExt {
176176 /// expansion originated from.
177177 fn original_file ( self , db : & dyn db:: ExpandDatabase ) -> FileId ;
178178
179+ fn original_file_respecting_includes ( self , db : & dyn db:: ExpandDatabase ) -> FileId ;
180+
179181 /// If this is a macro call, returns the syntax node of the call.
180182 fn call_node ( self , db : & dyn db:: ExpandDatabase ) -> Option < InFile < SyntaxNode > > ;
181183
@@ -215,6 +217,29 @@ impl HirFileIdExt for HirFileId {
215217 }
216218 }
217219
220+ fn original_file_respecting_includes ( mut self , db : & dyn db:: ExpandDatabase ) -> FileId {
221+ loop {
222+ match self . repr ( ) {
223+ base_db:: span:: HirFileIdRepr :: FileId ( id) => break id,
224+ base_db:: span:: HirFileIdRepr :: MacroFile ( file) => {
225+ let loc = db. lookup_intern_macro_call ( file. macro_call_id ) ;
226+ if loc. def . is_include ( ) {
227+ if let Some ( eager) = & loc. eager {
228+ if let Ok ( it) = builtin_fn_macro:: include_input_to_file_id (
229+ db,
230+ file. macro_call_id ,
231+ & eager. arg ,
232+ ) {
233+ break it;
234+ }
235+ }
236+ }
237+ self = loc. kind . file_id ( ) ;
238+ }
239+ }
240+ }
241+ }
242+
218243 fn call_node ( self , db : & dyn db:: ExpandDatabase ) -> Option < InFile < SyntaxNode > > {
219244 let macro_file = self . macro_file ( ) ?;
220245 let loc: MacroCallLoc = db. lookup_intern_macro_call ( macro_file. macro_call_id ) ;
@@ -473,7 +498,7 @@ impl MacroCallKind {
473498 }
474499
475500 /// Returns the file containing the macro invocation.
476- fn file_id ( & self ) -> HirFileId {
501+ pub fn file_id ( & self ) -> HirFileId {
477502 match * self {
478503 MacroCallKind :: FnLike { ast_id : InFile { file_id, .. } , .. }
479504 | MacroCallKind :: Derive { ast_id : InFile { file_id, .. } , .. }
0 commit comments