Skip to content

Commit 78503f2

Browse files
committed
feat: highlight tail expression in labeled block
1 parent c588273 commit 78503f2

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

crates/ide/src/highlight_related.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,18 @@ pub(crate) fn highlight_break_points(
446446
push_to_highlights(file_id, text_range);
447447
});
448448

449+
if matches!(expr, ast::Expr::BlockExpr(_)) {
450+
for_each_tail_expr(&expr, &mut |tail| {
451+
if matches!(tail, ast::Expr::BreakExpr(_)) {
452+
return;
453+
}
454+
455+
let file_id = sema.hir_file_for(tail.syntax());
456+
let range = tail.syntax().text_range();
457+
push_to_highlights(file_id, Some(range));
458+
});
459+
}
460+
449461
Some(highlights)
450462
}
451463

@@ -2072,4 +2084,21 @@ pub unsafe fn bootstrap() -> ! {
20722084
"#,
20732085
)
20742086
}
2087+
2088+
#[test]
2089+
fn labeled_block_tail_expr() {
2090+
check(
2091+
r#"
2092+
fn foo() {
2093+
'a: {
2094+
// ^^^
2095+
if true { break$0 'a 0; }
2096+
// ^^^^^^^^
2097+
5
2098+
// ^
2099+
}
2100+
}
2101+
"#,
2102+
);
2103+
}
20752104
}

0 commit comments

Comments
 (0)