diff options
| author | roifewu <roifewu@gmail.com> | 2025-04-15 12:59:22 +0800 |
|---|---|---|
| committer | roifewu <roifewu@gmail.com> | 2025-04-16 19:08:44 +0800 |
| commit | 9333cc7bede7a1cc68a586c2ea701099f9a73348 (patch) | |
| tree | b81b0f931883211e4c4cf5930c8836443959255d /src/tools/rust-analyzer/crates | |
| parent | a5395202592c3a6d55d6063817fb8fdbf275612f (diff) | |
| download | rust-9333cc7bede7a1cc68a586c2ea701099f9a73348.tar.gz rust-9333cc7bede7a1cc68a586c2ea701099f9a73348.zip | |
feat: highlight tail expr when cursor is on label
Diffstat (limited to 'src/tools/rust-analyzer/crates')
| -rw-r--r-- | src/tools/rust-analyzer/crates/ide/src/highlight_related.rs | 37 |
1 files changed, 37 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 8f84f35bb45..bb96c925190 100644 --- a/src/tools/rust-analyzer/crates/ide/src/highlight_related.rs +++ b/src/tools/rust-analyzer/crates/ide/src/highlight_related.rs @@ -232,6 +232,23 @@ fn highlight_references( } } + // highlight the tail expr of the labelled block + if matches!(def, Definition::Label(_)) { + let label = token.parent_ancestors().nth(1).and_then(ast::Label::cast); + if let Some(block) = + label.and_then(|label| label.syntax().parent()).and_then(ast::BlockExpr::cast) + { + for_each_tail_expr(&block.into(), &mut |tail| { + if !matches!(tail, ast::Expr::BreakExpr(_)) { + res.insert(HighlightedRange { + range: tail.syntax().text_range(), + category: ReferenceCategory::empty(), + }); + } + }); + } + } + // highlight the defs themselves match def { Definition::Local(local) => { @@ -2101,4 +2118,24 @@ fn foo() { "#, ); } + + #[test] + fn labeled_block_tail_expr_2() { + check( + r#" +fn foo() { + let _ = 'b$0lk: { + // ^^^^ + let x = 1; + if true { break 'blk 42; } + // ^^^^ + if false { break 'blk 24; } + // ^^^^ + 100 + // ^^^ + }; +} +"#, + ); + } } |
