@@ -148,7 +148,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
148148 self . imp . expand_attr_macro ( item)
149149 }
150150
151- pub fn expand_derive_macro ( & self , derive : & ast:: Attr ) -> Option < SyntaxNode > {
151+ pub fn expand_derive_macro ( & self , derive : & ast:: Attr ) -> Option < Vec < SyntaxNode > > {
152152 self . imp . expand_derive_macro ( derive)
153153 }
154154
@@ -389,16 +389,29 @@ impl<'db> SemanticsImpl<'db> {
389389 Some ( node)
390390 }
391391
392- fn expand_derive_macro ( & self , attr : & ast:: Attr ) -> Option < SyntaxNode > {
392+ fn expand_derive_macro ( & self , attr : & ast:: Attr ) -> Option < Vec < SyntaxNode > > {
393393 let item = attr. syntax ( ) . parent ( ) . and_then ( ast:: Item :: cast) ?;
394394 let sa = self . analyze ( item. syntax ( ) ) ;
395395 let item = InFile :: new ( sa. file_id , & item) ;
396396 let src = InFile :: new ( sa. file_id , attr. clone ( ) ) ;
397- let macro_call_id = self . with_ctx ( |ctx| ctx. attr_to_derive_macro_call ( item, src) ) ?;
398- let file_id = macro_call_id. as_file ( ) ;
399- let node = self . db . parse_or_expand ( file_id) ?;
400- self . cache ( node. clone ( ) , file_id) ;
401- Some ( node)
397+ self . with_ctx ( |ctx| {
398+ let macro_call_ids = ctx. attr_to_derive_macro_call ( item, src) ?;
399+
400+ let expansions: Vec < _ > = macro_call_ids
401+ . iter ( )
402+ . map ( |call| call. as_file ( ) )
403+ . flat_map ( |file_id| {
404+ let node = self . db . parse_or_expand ( file_id) ?;
405+ self . cache ( node. clone ( ) , file_id) ;
406+ Some ( node)
407+ } )
408+ . collect ( ) ;
409+ if expansions. is_empty ( ) {
410+ None
411+ } else {
412+ Some ( expansions)
413+ }
414+ } )
402415 }
403416
404417 fn is_attr_macro_call ( & self , item : & ast:: Item ) -> bool {
0 commit comments