Skip to content

Commit

Permalink
Only Highlight Exit Points on async Token
Browse files Browse the repository at this point in the history
This ensures that when being on an `await` token, it still only
highlights the yield points and not the exit points.
  • Loading branch information
CryZe committed Oct 8, 2024
1 parent 0012480 commit 4b30d25
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/tools/rust-analyzer/crates/ide/src/highlight_related.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,16 +513,23 @@ pub(crate) fn highlight_yield_points(
match anc {
ast::Fn(fn_) => hl(sema, fn_.async_token(), fn_.body().map(ast::Expr::BlockExpr)),
ast::BlockExpr(block_expr) => {
if block_expr.async_token().is_none() {
let Some(async_token) = block_expr.async_token() else {
continue;
}
};

// Async blocks act similar to closures. So we want to
// highlight their exit points too.
let exit_points = hl_exit_points(sema, block_expr.async_token(), block_expr.clone().into());
merge_map(&mut res, exit_points);
// highlight their exit points too, but only if we are on
// the async token.
if async_token == token {
let exit_points = hl_exit_points(
sema,
Some(async_token.clone()),
block_expr.clone().into(),
);
merge_map(&mut res, exit_points);
}

hl(sema, block_expr.async_token(), Some(block_expr.into()))
hl(sema, Some(async_token), Some(block_expr.into()))
},
ast::ClosureExpr(closure) => hl(sema, closure.async_token(), closure.body()),
_ => continue,
Expand Down Expand Up @@ -949,7 +956,6 @@ async fn foo() {
(async {
// ^^^^^
(async { 0.await }).await$0
// ^^^^^^^^^^^^^^^^^^^^^^^^^
// ^^^^^
}).await;
}
Expand Down

0 comments on commit 4b30d25

Please sign in to comment.