@@ -148,7 +148,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
148
148
self . imp . expand_attr_macro ( item)
149
149
}
150
150
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 > > {
152
152
self . imp . expand_derive_macro ( derive)
153
153
}
154
154
@@ -389,16 +389,29 @@ impl<'db> SemanticsImpl<'db> {
389
389
Some ( node)
390
390
}
391
391
392
- fn expand_derive_macro ( & self , attr : & ast:: Attr ) -> Option < SyntaxNode > {
392
+ fn expand_derive_macro ( & self , attr : & ast:: Attr ) -> Option < Vec < SyntaxNode > > {
393
393
let item = attr. syntax ( ) . parent ( ) . and_then ( ast:: Item :: cast) ?;
394
394
let sa = self . analyze ( item. syntax ( ) ) ;
395
395
let item = InFile :: new ( sa. file_id , & item) ;
396
396
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
+ } )
402
415
}
403
416
404
417
fn is_attr_macro_call ( & self , item : & ast:: Item ) -> bool {
0 commit comments