diff options
| author | roifewu <roifewu@gmail.com> | 2025-04-10 02:45:11 +0800 |
|---|---|---|
| committer | roifewu <roifewu@gmail.com> | 2025-04-15 12:58:38 +0800 |
| commit | a5395202592c3a6d55d6063817fb8fdbf275612f (patch) | |
| tree | dbce90c1980372433cfd89d6cadc395c648a186d | |
| parent | 50f3e01399ca15ed582e62c040a21ad4aee494c8 (diff) | |
| download | rust-a5395202592c3a6d55d6063817fb8fdbf275612f.tar.gz rust-a5395202592c3a6d55d6063817fb8fdbf275612f.zip | |
feat: highlight tail expression in labeled block
| -rw-r--r-- | src/tools/rust-analyzer/crates/ide/src/highlight_related.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/tools/rust-analyzer/crates/ide/src/highlight_related.rs b/src/tools/rust-analyzer/crates/ide/src/highlight_related.rs index 201f8687608..8f84f35bb45 100644 --- a/src/tools/rust-analyzer/crates/ide/src/highlight_related.rs +++ b/src/tools/rust-analyzer/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 + // ^ + } +} +"#, + ); + } } |
