@@ -722,13 +722,12 @@ fn orig_range_with_focus(
722
722
value : & SyntaxNode ,
723
723
name : Option < impl AstNode > ,
724
724
) -> UpmappingResult < ( FileRange , Option < TextRange > ) > {
725
+ value;
726
+ name. as_ref ( ) . map ( |it| it. syntax ( ) ) ;
725
727
let Some ( name) = name else { return orig_range ( db, hir_file, value) } ;
726
728
727
- let call_range = || {
728
- db. lookup_intern_macro_call ( hir_file. macro_file ( ) . unwrap ( ) . macro_call_id )
729
- . kind
730
- . original_call_range ( db)
731
- } ;
729
+ let call_kind =
730
+ || db. lookup_intern_macro_call ( hir_file. macro_file ( ) . unwrap ( ) . macro_call_id ) . kind ;
732
731
733
732
let def_range = || {
734
733
db. lookup_intern_macro_call ( hir_file. macro_file ( ) . unwrap ( ) . macro_call_id )
@@ -755,7 +754,22 @@ fn orig_range_with_focus(
755
754
}
756
755
// name lies outside the node, so instead point to the macro call which
757
756
// *should* contain the name
758
- _ => call_range ( ) ,
757
+ _ => {
758
+ let kind = call_kind ( ) ;
759
+ let range = kind. clone ( ) . original_call_range_with_body ( db) ;
760
+ //If the focus range is in the attribute/derive body, we
761
+ // need to point the call site to the entire body, if not, fall back
762
+ // to the name range of the attribute/derive call
763
+ // FIXME: Do this differently, this is very inflexible the caller
764
+ // should choose this behavior
765
+ if range. file_id == focus_range. file_id
766
+ && range. range . contains_range ( focus_range. range )
767
+ {
768
+ range
769
+ } else {
770
+ kind. original_call_range ( db)
771
+ }
772
+ }
759
773
} ,
760
774
Some ( focus_range) ,
761
775
) ,
@@ -784,7 +798,7 @@ fn orig_range_with_focus(
784
798
// node is in macro def, just show the focus
785
799
_ => (
786
800
// show the macro call
787
- ( call_range ( ) , None ) ,
801
+ ( call_kind ( ) . original_call_range ( db ) , None ) ,
788
802
Some ( ( focus_range, Some ( focus_range) ) ) ,
789
803
) ,
790
804
}
0 commit comments