@@ -26,7 +26,7 @@ use hir_def::{
2626 } ,
2727 hir:: { BindingId , Expr , ExprId , ExprOrPatId , Pat } ,
2828 lang_item:: LangItem ,
29- nameres:: { MacroSubNs , crate_def_map} ,
29+ nameres:: { MacroSubNs , block_def_map , crate_def_map} ,
3030 resolver:: { HasResolver , Resolver , TypeNs , ValueNs , resolver_for_scope} ,
3131 type_ref:: { Mutability , TypeRefId } ,
3232} ;
@@ -218,8 +218,16 @@ impl<'db> SourceAnalyzer<'db> {
218218 } )
219219 }
220220
221- pub ( crate ) fn expansion ( & self , node : InFile < & ast:: MacroCall > ) -> Option < MacroCallId > {
222- self . store_sm ( ) ?. expansion ( node)
221+ pub ( crate ) fn expansion (
222+ & self ,
223+ db : & dyn HirDatabase ,
224+ macro_call : InFile < & ast:: MacroCall > ,
225+ ) -> Option < MacroCallId > {
226+ self . store_sm ( ) . and_then ( |sm| sm. expansion ( macro_call) ) . or_else ( || {
227+ let ast_id_map = db. ast_id_map ( macro_call. file_id ) ;
228+ let call_ast_id = macro_call. with_value ( ast_id_map. ast_id ( macro_call. value ) ) ;
229+ self . resolver . item_scopes ( ) . find_map ( |scope| scope. macro_invoc ( call_ast_id) )
230+ } )
223231 }
224232
225233 fn trait_environment ( & self , db : & ' db dyn HirDatabase ) -> Arc < TraitEnvironment > {
@@ -747,17 +755,16 @@ impl<'db> SourceAnalyzer<'db> {
747755
748756 pub ( crate ) fn resolve_macro_call (
749757 & self ,
750- db : & ' db dyn HirDatabase ,
758+ db : & dyn HirDatabase ,
751759 macro_call : InFile < & ast:: MacroCall > ,
752760 ) -> Option < Macro > {
753- let bs = self . store_sm ( ) ?;
754- bs. expansion ( macro_call) . and_then ( |it| {
755- // FIXME: Block def maps
761+ self . expansion ( db, macro_call) . and_then ( |it| {
756762 let def = it. lookup ( db) . def ;
757- crate_def_map ( db, def. krate )
758- . macro_def_to_macro_id
759- . get ( & def. kind . erased_ast_id ( ) )
760- . map ( |it| ( * it) . into ( ) )
763+ let def_map = match def. block {
764+ Some ( block) => block_def_map ( db, base_db:: salsa:: plumbing:: FromId :: from_id ( block) ) ,
765+ None => crate_def_map ( db, def. krate ) ,
766+ } ;
767+ def_map. macro_def_to_macro_id . get ( & def. kind . erased_ast_id ( ) ) . map ( |it| ( * it) . into ( ) )
761768 } )
762769 }
763770
@@ -1292,18 +1299,6 @@ impl<'db> SourceAnalyzer<'db> {
12921299 . collect ( )
12931300 }
12941301
1295- pub ( crate ) fn expand (
1296- & self ,
1297- db : & ' db dyn HirDatabase ,
1298- macro_call : InFile < & ast:: MacroCall > ,
1299- ) -> Option < MacroCallId > {
1300- self . store_sm ( ) . and_then ( |bs| bs. expansion ( macro_call) ) . or_else ( || {
1301- self . resolver . item_scope ( ) . macro_invoc (
1302- macro_call. with_value ( db. ast_id_map ( macro_call. file_id ) . ast_id ( macro_call. value ) ) ,
1303- )
1304- } )
1305- }
1306-
13071302 pub ( crate ) fn resolve_variant ( & self , record_lit : ast:: RecordExpr ) -> Option < VariantId > {
13081303 let infer = self . infer ( ) ?;
13091304 let expr_id = self . expr_id ( record_lit. into ( ) ) ?;
0 commit comments