@@ -226,6 +226,7 @@ fn try_find_fn_or_closure(
226226 sema : & Semantics < ' _ , RootDatabase > ,
227227 file_id : HirFileId ,
228228 ancestors : impl Iterator < Item = SyntaxNode > ,
229+ cursor_token_kind : SyntaxKind ,
229230 ) -> Option < UpmappingResult < NavigationTarget > > {
230231 let db = sema. db ;
231232
@@ -238,7 +239,11 @@ fn try_find_fn_or_closure(
238239
239240 // For async token, we navigate to itself, which triggers
240241 // 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+ } ;
242247 let focus_range = InFile :: new( file_id, focus_token. text_range( ) )
243248 . original_node_file_range_opt( db)
244249 . map( |( frange, _) | frange. range) ;
@@ -276,21 +281,22 @@ fn try_find_fn_or_closure(
276281 None
277282 }
278283
284+ let token_kind = token. kind ( ) ;
279285 sema. descend_into_macros ( DescendPreference :: None , token. clone ( ) )
280286 . into_iter ( )
281287 . filter_map ( |descended| {
282288 let file_id = sema. hir_file_for ( & descended. parent ( ) ?) ;
283289
284290 // 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 ( || {
286292 // If not found, try to find it in the root file
287293 if file_id. is_macro ( ) {
288294 token
289295 . parent_ancestors ( )
290296 . find ( |it| ast:: TokenTree :: can_cast ( it. kind ( ) ) )
291297 . and_then ( |parent| {
292298 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 )
294300 } )
295301 } else {
296302 None
0 commit comments