Skip to content

Commit 68c263b

Browse files
committed
Only Highlight Exit Points on async Token
This ensures that when being on an `await` token, it still only highlights the yield points and not the exit points.
1 parent e1961b1 commit 68c263b

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

crates/ide/src/highlight_related.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -513,16 +513,23 @@ pub(crate) fn highlight_yield_points(
513513
match anc {
514514
ast::Fn(fn_) => hl(sema, fn_.async_token(), fn_.body().map(ast::Expr::BlockExpr)),
515515
ast::BlockExpr(block_expr) => {
516-
if block_expr.async_token().is_none() {
516+
let Some(async_token) = block_expr.async_token() else {
517517
continue;
518-
}
518+
};
519519

520520
// Async blocks act similar to closures. So we want to
521-
// highlight their exit points too.
522-
let exit_points = hl_exit_points(sema, block_expr.async_token(), block_expr.clone().into());
523-
merge_map(&mut res, exit_points);
521+
// highlight their exit points too, but only if we are on
522+
// the async token.
523+
if async_token == token {
524+
let exit_points = hl_exit_points(
525+
sema,
526+
Some(async_token.clone()),
527+
block_expr.clone().into(),
528+
);
529+
merge_map(&mut res, exit_points);
530+
}
524531

525-
hl(sema, block_expr.async_token(), Some(block_expr.into()))
532+
hl(sema, Some(async_token), Some(block_expr.into()))
526533
},
527534
ast::ClosureExpr(closure) => hl(sema, closure.async_token(), closure.body()),
528535
_ => continue,
@@ -949,7 +956,6 @@ async fn foo() {
949956
(async {
950957
// ^^^^^
951958
(async { 0.await }).await$0
952-
// ^^^^^^^^^^^^^^^^^^^^^^^^^
953959
// ^^^^^
954960
}).await;
955961
}

0 commit comments

Comments
 (0)