@@ -628,35 +628,42 @@ fn emit_def_diagnostic(db: &dyn HirDatabase, acc: &mut Vec<AnyDiagnostic>, diag:
628
628
}
629
629
630
630
DefDiagnosticKind :: UnresolvedProcMacro { ast } => {
631
- let mut precise_location = None ;
632
- let ( node, macro_name) = match ast {
631
+ let ( node, precise_location, macro_name) = match ast {
633
632
MacroCallKind :: FnLike { ast_id, .. } => {
634
633
let node = ast_id. to_node ( db. upcast ( ) ) ;
635
- ( ast_id. with_value ( SyntaxNodePtr :: from ( AstPtr :: new ( & node) ) ) , None )
634
+ (
635
+ ast_id. with_value ( SyntaxNodePtr :: from ( AstPtr :: new ( & node) ) ) ,
636
+ node. path ( ) . map ( |it| it. syntax ( ) . text_range ( ) ) ,
637
+ node. path ( ) . and_then ( |it| it. segment ( ) ) . map ( |it| it. to_string ( ) ) ,
638
+ )
636
639
}
637
640
MacroCallKind :: Derive { ast_id, derive_attr_index, derive_index } => {
638
641
let node = ast_id. to_node ( db. upcast ( ) ) ;
639
-
640
642
// Compute the precise location of the macro name's token in the derive
641
643
// list.
642
644
let token = ( || {
643
- let derive_attr = node. attrs ( ) . nth ( * derive_attr_index as usize ) ?;
644
- derive_attr
645
+ let derive_attr = node
646
+ . doc_comments_and_attrs ( )
647
+ . nth ( * derive_attr_index as usize )
648
+ . and_then ( Either :: left) ?;
649
+ let token_tree = derive_attr. meta ( ) ?. token_tree ( ) ?;
650
+ let group_by = token_tree
645
651
. syntax ( )
646
652
. children_with_tokens ( )
647
653
. filter_map ( |elem| match elem {
648
654
syntax:: NodeOrToken :: Token ( tok) => Some ( tok) ,
649
655
_ => None ,
650
656
} )
651
- . group_by ( |t| t. kind ( ) == T ! [ , ] )
657
+ . group_by ( |t| t. kind ( ) == T ! [ , ] ) ;
658
+ let ( _, mut group) = group_by
652
659
. into_iter ( )
653
660
. filter ( |& ( comma, _) | !comma)
654
- . nth ( * derive_index as usize )
655
- . and_then ( | ( _ , mut g ) | g . find ( |t| t. kind ( ) == T ! [ ident] ) )
661
+ . nth ( * derive_index as usize ) ? ;
662
+ group . find ( |t| t. kind ( ) == T ! [ ident] )
656
663
} ) ( ) ;
657
- precise_location = token. as_ref ( ) . map ( |tok| tok. text_range ( ) ) ;
658
664
(
659
665
ast_id. with_value ( SyntaxNodePtr :: from ( AstPtr :: new ( & node) ) ) ,
666
+ token. as_ref ( ) . map ( |tok| tok. text_range ( ) ) ,
660
667
token. as_ref ( ) . map ( ToString :: to_string) ,
661
668
)
662
669
}
@@ -667,8 +674,10 @@ fn emit_def_diagnostic(db: &dyn HirDatabase, acc: &mut Vec<AnyDiagnostic>, diag:
667
674
. nth ( ( * invoc_attr_index) as usize )
668
675
. and_then ( Either :: left)
669
676
. unwrap_or_else ( || panic ! ( "cannot find attribute #{}" , invoc_attr_index) ) ;
677
+
670
678
(
671
679
ast_id. with_value ( SyntaxNodePtr :: from ( AstPtr :: new ( & attr) ) ) ,
680
+ Some ( attr. syntax ( ) . text_range ( ) ) ,
672
681
attr. path ( )
673
682
. and_then ( |path| path. segment ( ) )
674
683
. and_then ( |seg| seg. name_ref ( ) )
0 commit comments