Unnamed repository; edit this file 'description' to name the repository.
feat: highlight tail expression in labeled block
roifewu 2025-04-15
parent c588273 · commit 78503f2
-rw-r--r--crates/ide/src/highlight_related.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/crates/ide/src/highlight_related.rs b/crates/ide/src/highlight_related.rs
index 201f868760..8f84f35bb4 100644
--- a/crates/ide/src/highlight_related.rs
+++ b/crates/ide/src/highlight_related.rs
@@ -446,6 +446,18 @@ pub(crate) fn highlight_break_points(
push_to_highlights(file_id, text_range);
});
+ if matches!(expr, ast::Expr::BlockExpr(_)) {
+ for_each_tail_expr(&expr, &mut |tail| {
+ if matches!(tail, ast::Expr::BreakExpr(_)) {
+ return;
+ }
+
+ let file_id = sema.hir_file_for(tail.syntax());
+ let range = tail.syntax().text_range();
+ push_to_highlights(file_id, Some(range));
+ });
+ }
+
Some(highlights)
}
@@ -2072,4 +2084,21 @@ pub unsafe fn bootstrap() -> ! {
"#,
)
}
+
+ #[test]
+ fn labeled_block_tail_expr() {
+ check(
+ r#"
+fn foo() {
+ 'a: {
+ // ^^^
+ if true { break$0 'a 0; }
+ // ^^^^^^^^
+ 5
+ // ^
+ }
+}
+"#,
+ );
+ }
}