@@ -226,6 +226,7 @@ fn try_find_fn_or_closure(
226
226
sema : & Semantics < ' _ , RootDatabase > ,
227
227
file_id : HirFileId ,
228
228
ancestors : impl Iterator < Item = SyntaxNode > ,
229
+ cursor_token_kind : SyntaxKind ,
229
230
) -> Option < UpmappingResult < NavigationTarget > > {
230
231
let db = sema. db ;
231
232
@@ -238,7 +239,11 @@ fn try_find_fn_or_closure(
238
239
239
240
// For async token, we navigate to itself, which triggers
240
241
// VSCode to find the references
241
- let focus_token = fn_. fn_token( ) ?;
242
+ let focus_token = if matches!( cursor_token_kind, T ![ async ] ) {
243
+ fn_. async_token( ) ?
244
+ } else {
245
+ fn_. fn_token( ) ?
246
+ } ;
242
247
let focus_range = InFile :: new( file_id, focus_token. text_range( ) )
243
248
. original_node_file_range_opt( db)
244
249
. map( |( frange, _) | frange. range) ;
@@ -276,21 +281,22 @@ fn try_find_fn_or_closure(
276
281
None
277
282
}
278
283
284
+ let token_kind = token. kind ( ) ;
279
285
sema. descend_into_macros ( DescendPreference :: None , token. clone ( ) )
280
286
. into_iter ( )
281
287
. filter_map ( |descended| {
282
288
let file_id = sema. hir_file_for ( & descended. parent ( ) ?) ;
283
289
284
290
// Try to find the function in the macro file
285
- find_exit_point ( sema, file_id, descended. parent_ancestors ( ) ) . or_else ( || {
291
+ find_exit_point ( sema, file_id, descended. parent_ancestors ( ) , token_kind ) . or_else ( || {
286
292
// If not found, try to find it in the root file
287
293
if file_id. is_macro ( ) {
288
294
token
289
295
. parent_ancestors ( )
290
296
. find ( |it| ast:: TokenTree :: can_cast ( it. kind ( ) ) )
291
297
. and_then ( |parent| {
292
298
let file_id = sema. hir_file_for ( & parent) ;
293
- find_exit_point ( sema, file_id, parent. ancestors ( ) )
299
+ find_exit_point ( sema, file_id, parent. ancestors ( ) , token_kind )
294
300
} )
295
301
} else {
296
302
None
0 commit comments