@@ -25,12 +25,14 @@ use crate::{
2525 EagerCallLoc , EagerMacroId , InFile , MacroCallId , MacroCallKind , MacroDefId , MacroDefKind ,
2626} ;
2727
28+ use ra_db:: CrateId ;
2829use ra_parser:: FragmentKind ;
2930use ra_syntax:: { algo:: SyntaxRewriter , SyntaxNode } ;
3031use std:: sync:: Arc ;
3132
3233pub fn expand_eager_macro (
3334 db : & dyn AstDatabase ,
35+ krate : CrateId ,
3436 macro_call : InFile < ast:: MacroCall > ,
3537 def : MacroDefId ,
3638 resolver : & dyn Fn ( ast:: Path ) -> Option < MacroDefId > ,
@@ -47,6 +49,7 @@ pub fn expand_eager_macro(
4749 def,
4850 fragment : FragmentKind :: Expr ,
4951 subtree : Arc :: new ( parsed_args. clone ( ) ) ,
52+ krate,
5053 file_id : macro_call. file_id ,
5154 }
5255 } ) ;
@@ -56,14 +59,20 @@ pub fn expand_eager_macro(
5659 let result = eager_macro_recur (
5760 db,
5861 InFile :: new ( arg_file_id. as_file ( ) , parsed_args. syntax_node ( ) ) ,
62+ krate,
5963 resolver,
6064 ) ?;
6165 let subtree = to_subtree ( & result) ?;
6266
6367 if let MacroDefKind :: BuiltInEager ( eager) = def. kind {
6468 let ( subtree, fragment) = eager. expand ( db, arg_id, & subtree) . ok ( ) ?;
65- let eager =
66- EagerCallLoc { def, fragment, subtree : Arc :: new ( subtree) , file_id : macro_call. file_id } ;
69+ let eager = EagerCallLoc {
70+ def,
71+ fragment,
72+ subtree : Arc :: new ( subtree) ,
73+ krate,
74+ file_id : macro_call. file_id ,
75+ } ;
6776
6877 Some ( db. intern_eager_expansion ( eager) )
6978 } else {
@@ -81,18 +90,20 @@ fn lazy_expand(
8190 db : & dyn AstDatabase ,
8291 def : & MacroDefId ,
8392 macro_call : InFile < ast:: MacroCall > ,
93+ krate : CrateId ,
8494) -> Option < InFile < SyntaxNode > > {
8595 let ast_id = db. ast_id_map ( macro_call. file_id ) . ast_id ( & macro_call. value ) ;
8696
8797 let id: MacroCallId =
88- def. as_lazy_macro ( db, MacroCallKind :: FnLike ( macro_call. with_value ( ast_id) ) ) . into ( ) ;
98+ def. as_lazy_macro ( db, krate , MacroCallKind :: FnLike ( macro_call. with_value ( ast_id) ) ) . into ( ) ;
8999
90100 db. parse_or_expand ( id. as_file ( ) ) . map ( |node| InFile :: new ( id. as_file ( ) , node) )
91101}
92102
93103fn eager_macro_recur (
94104 db : & dyn AstDatabase ,
95105 curr : InFile < SyntaxNode > ,
106+ krate : CrateId ,
96107 macro_resolver : & dyn Fn ( ast:: Path ) -> Option < MacroDefId > ,
97108) -> Option < SyntaxNode > {
98109 let original = curr. value . clone ( ) ;
@@ -105,18 +116,23 @@ fn eager_macro_recur(
105116 let def: MacroDefId = macro_resolver ( child. path ( ) ?) ?;
106117 let insert = match def. kind {
107118 MacroDefKind :: BuiltInEager ( _) => {
108- let id: MacroCallId =
109- expand_eager_macro ( db, curr. with_value ( child. clone ( ) ) , def, macro_resolver) ?
110- . into ( ) ;
119+ let id: MacroCallId = expand_eager_macro (
120+ db,
121+ krate,
122+ curr. with_value ( child. clone ( ) ) ,
123+ def,
124+ macro_resolver,
125+ ) ?
126+ . into ( ) ;
111127 db. parse_or_expand ( id. as_file ( ) ) ?
112128 }
113129 MacroDefKind :: Declarative
114130 | MacroDefKind :: BuiltIn ( _)
115131 | MacroDefKind :: BuiltInDerive ( _)
116132 | MacroDefKind :: CustomDerive ( _) => {
117- let expanded = lazy_expand ( db, & def, curr. with_value ( child. clone ( ) ) ) ?;
133+ let expanded = lazy_expand ( db, & def, curr. with_value ( child. clone ( ) ) , krate ) ?;
118134 // replace macro inside
119- eager_macro_recur ( db, expanded, macro_resolver) ?
135+ eager_macro_recur ( db, expanded, krate , macro_resolver) ?
120136 }
121137 } ;
122138
0 commit comments