@@ -688,8 +688,11 @@ impl MacroCallKind {
688
688
689
689
/// Returns the original file range that best describes the location of this macro call.
690
690
///
691
- /// Unlike `MacroCallKind::original_call_range`, this also spans the item of attributes and derives.
692
- pub fn original_call_range_with_body ( self , db : & dyn ExpandDatabase ) -> FileRange {
691
+ /// This spans the entire macro call, including its input. That is for
692
+ /// - fn_like! {}, it spans the path and token tree
693
+ /// - #\[derive], it spans the `#[derive(...)]` attribute and the annotated item
694
+ /// - #\[attr], it spans the `#[attr(...)]` attribute and the annotated item
695
+ pub fn original_call_range_with_input ( self , db : & dyn ExpandDatabase ) -> FileRange {
693
696
let mut kind = self ;
694
697
let file_id = loop {
695
698
match kind. file_id ( ) {
@@ -712,8 +715,8 @@ impl MacroCallKind {
712
715
/// Returns the original file range that best describes the location of this macro call.
713
716
///
714
717
/// Here we try to roughly match what rustc does to improve diagnostics: fn-like macros
715
- /// get the whole `ast::MacroCall`, attribute macros get the attribute's range, and derives
716
- /// get only the specific derive that is being referred to.
718
+ /// get the macro path (rustc shows the whole `ast::MacroCall`) , attribute macros get the
719
+ /// attribute's range, and derives get only the specific derive that is being referred to.
717
720
pub fn original_call_range ( self , db : & dyn ExpandDatabase ) -> FileRange {
718
721
let mut kind = self ;
719
722
let file_id = loop {
@@ -726,7 +729,14 @@ impl MacroCallKind {
726
729
} ;
727
730
728
731
let range = match kind {
729
- MacroCallKind :: FnLike { ast_id, .. } => ast_id. to_ptr ( db) . text_range ( ) ,
732
+ MacroCallKind :: FnLike { ast_id, .. } => {
733
+ let node = ast_id. to_node ( db) ;
734
+ node. path ( )
735
+ . unwrap ( )
736
+ . syntax ( )
737
+ . text_range ( )
738
+ . cover ( node. excl_token ( ) . unwrap ( ) . text_range ( ) )
739
+ }
730
740
MacroCallKind :: Derive { ast_id, derive_attr_index, .. } => {
731
741
// FIXME: should be the range of the macro name, not the whole derive
732
742
// FIXME: handle `cfg_attr`
0 commit comments