@@ -10,6 +10,7 @@ use crate::quote;
1010
1111#[ derive( Debug ,  Clone ,  Copy ,  PartialEq ,  Eq ,  Hash ) ]  
1212pub  enum  BuiltinExpander  { 
13+     File , 
1314    Line , 
1415    Stringify , 
1516} 
@@ -22,6 +23,7 @@ impl BuiltinExpander {
2223        tt :  & tt:: Subtree , 
2324    )  -> Result < tt:: Subtree ,  mbe:: ExpandError >  { 
2425        match  self  { 
26+             BuiltinExpander :: File  => file_expand ( db,  id,  tt) , 
2527            BuiltinExpander :: Line  => line_expand ( db,  id,  tt) , 
2628            BuiltinExpander :: Stringify  => stringify_expand ( db,  id,  tt) , 
2729        } 
@@ -34,7 +36,9 @@ pub fn find_builtin_macro(
3436    ast_id :  AstId < ast:: MacroCall > , 
3537)  -> Option < MacroDefId >  { 
3638    // FIXME: Better registering method 
37-     if  ident == & name:: LINE_MACRO  { 
39+     if  ident == & name:: FILE_MACRO  { 
40+         Some ( MacroDefId  {  krate,  ast_id,  kind :  MacroDefKind :: BuiltIn ( BuiltinExpander :: File )  } ) 
41+     }  else  if  ident == & name:: LINE_MACRO  { 
3842        Some ( MacroDefId  {  krate,  ast_id,  kind :  MacroDefKind :: BuiltIn ( BuiltinExpander :: Line )  } ) 
3943    }  else  if  ident == & name:: STRINGIFY_MACRO  { 
4044        Some ( MacroDefId  {  krate,  ast_id,  kind :  MacroDefKind :: BuiltIn ( BuiltinExpander :: Stringify )  } ) 
@@ -105,3 +109,23 @@ fn stringify_expand(
105109
106110    Ok ( expanded) 
107111} 
112+ 
113+ fn  file_expand ( 
114+     db :  & dyn  AstDatabase , 
115+     id :  MacroCallId , 
116+     _tt :  & tt:: Subtree , 
117+ )  -> Result < tt:: Subtree ,  mbe:: ExpandError >  { 
118+     let  loc = db. lookup_intern_macro ( id) ; 
119+     let  macro_call = loc. ast_id . to_node ( db) ; 
120+     let  _ = macro_call. token_tree ( ) . ok_or_else ( || mbe:: ExpandError :: UnexpectedToken ) ?; 
121+ 
122+     // FIXME: RA purposefully lacks knowledge of absolute file names 
123+     // so just return "". 
124+     let  file_name = "" ; 
125+ 
126+     let  expanded = quote !  { 
127+         #file_name
128+     } ; 
129+ 
130+     Ok ( expanded) 
131+ } 
0 commit comments