@@ -180,11 +180,25 @@ fn hover_simple(
180180
181181 // prefer descending the same token kind in attribute expansions, in normal macros text
182182 // equivalency is more important
183- let mut descended = vec ! [ ] ;
184- sema. descend_into_macros_cb ( original_token. clone ( ) , |token| {
185- descended. push ( token. value ) ;
183+ let mut descended = sema. descend_into_macros ( original_token. clone ( ) ) ;
184+
185+ let kind = original_token. kind ( ) ;
186+ let text = original_token. text ( ) ;
187+ let ident_kind = kind. is_any_identifier ( ) ;
188+
189+ descended. sort_by_key ( |tok| {
190+ let tok_kind = tok. kind ( ) ;
191+
192+ let exact_same_kind = tok_kind == kind;
193+ let both_idents = exact_same_kind || ( tok_kind. is_any_identifier ( ) && ident_kind) ;
194+ let same_text = tok. text ( ) == text;
195+ // anything that mapped into a token tree has likely no semantic information
196+ let no_tt_parent = tok. parent ( ) . map_or ( false , |it| it. kind ( ) != TOKEN_TREE ) ;
197+ ( both_idents as usize )
198+ | ( ( exact_same_kind as usize ) << 1 )
199+ | ( ( same_text as usize ) << 2 )
200+ | ( ( no_tt_parent as usize ) << 3 )
186201 } ) ;
187- let descended = || descended. iter ( ) ;
188202
189203 // TODO: WE should not try these step by step, instead to accommodate for macros we should run
190204 // all of these in "parallel" and rank their results
0 commit comments