feat: highlight tail expr when cursor is on label
This commit is contained in:
parent
a539520259
commit
9333cc7bed
1 changed files with 37 additions and 0 deletions
|
|
@ -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) => {
|
||||
|
|
@ -2098,6 +2115,26 @@ 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
|
||||
// ^^^
|
||||
};
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue