mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
refactor helper function to work with function taking expression enum instead of break expression
This commit is contained in:
parent
1c074499f3
commit
cad0cf6950
2 changed files with 15 additions and 10 deletions
|
@ -197,11 +197,14 @@ fn highlight_break_points(token: SyntaxToken) -> Option<Vec<HighlightedRange>> {
|
||||||
label.as_ref().map(|it| it.syntax().text_range()),
|
label.as_ref().map(|it| it.syntax().text_range()),
|
||||||
);
|
);
|
||||||
highlights.extend(range.map(|range| HighlightedRange { category: None, range }));
|
highlights.extend(range.map(|range| HighlightedRange { category: None, range }));
|
||||||
for_each_break_expr(label, body, &mut |break_| {
|
for_each_break_expr(label, body, &mut |expr| {
|
||||||
let range = cover_range(
|
let range: Option<TextRange> = match expr {
|
||||||
|
ast::Expr::BreakExpr(break_) => cover_range(
|
||||||
break_.break_token().map(|it| it.text_range()),
|
break_.break_token().map(|it| it.text_range()),
|
||||||
break_.lifetime().map(|it| it.syntax().text_range()),
|
break_.lifetime().map(|it| it.syntax().text_range()),
|
||||||
);
|
),
|
||||||
|
_ => None,
|
||||||
|
};
|
||||||
highlights.extend(range.map(|range| HighlightedRange { category: None, range }));
|
highlights.extend(range.map(|range| HighlightedRange { category: None, range }));
|
||||||
});
|
});
|
||||||
Some(highlights)
|
Some(highlights)
|
||||||
|
|
|
@ -121,7 +121,7 @@ pub fn for_each_tail_expr(expr: &ast::Expr, cb: &mut dyn FnMut(&ast::Expr)) {
|
||||||
|
|
||||||
Some(ast::BlockModifier::Label(label)) => {
|
Some(ast::BlockModifier::Label(label)) => {
|
||||||
for_each_break_expr(Some(label), b.stmt_list(), &mut |b| {
|
for_each_break_expr(Some(label), b.stmt_list(), &mut |b| {
|
||||||
cb(&ast::Expr::BreakExpr(b))
|
cb(&b)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Some(ast::BlockModifier::Unsafe(_)) => (),
|
Some(ast::BlockModifier::Unsafe(_)) => (),
|
||||||
|
@ -151,12 +151,14 @@ pub fn for_each_tail_expr(expr: &ast::Expr, cb: &mut dyn FnMut(&ast::Expr)) {
|
||||||
}
|
}
|
||||||
ast::Expr::LoopExpr(l) => {
|
ast::Expr::LoopExpr(l) => {
|
||||||
for_each_break_expr(l.label(), l.loop_body().and_then(|it| it.stmt_list()), &mut |b| {
|
for_each_break_expr(l.label(), l.loop_body().and_then(|it| it.stmt_list()), &mut |b| {
|
||||||
cb(&ast::Expr::BreakExpr(b))
|
cb(&b)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
ast::Expr::MatchExpr(m) => {
|
ast::Expr::MatchExpr(m) => {
|
||||||
if let Some(arms) = m.match_arm_list() {
|
if let Some(arms) = m.match_arm_list() {
|
||||||
arms.arms().filter_map(|arm| arm.expr()).for_each(|e| for_each_tail_expr(&e, cb));
|
arms.arms().filter_map(|arm| arm.expr()).for_each(|e| for_each_tail_expr(&e, &mut |b| {
|
||||||
|
cb(&b)
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast::Expr::ArrayExpr(_)
|
ast::Expr::ArrayExpr(_)
|
||||||
|
@ -194,7 +196,7 @@ pub fn for_each_tail_expr(expr: &ast::Expr, cb: &mut dyn FnMut(&ast::Expr)) {
|
||||||
pub fn for_each_break_expr(
|
pub fn for_each_break_expr(
|
||||||
label: Option<ast::Label>,
|
label: Option<ast::Label>,
|
||||||
body: Option<ast::StmtList>,
|
body: Option<ast::StmtList>,
|
||||||
cb: &mut dyn FnMut(ast::BreakExpr),
|
cb: &mut dyn FnMut(ast::Expr),
|
||||||
) {
|
) {
|
||||||
let label = label.and_then(|lbl| lbl.lifetime());
|
let label = label.and_then(|lbl| lbl.lifetime());
|
||||||
let mut depth = 0;
|
let mut depth = 0;
|
||||||
|
@ -217,7 +219,7 @@ pub fn for_each_break_expr(
|
||||||
ast::Expr::BreakExpr(b)
|
ast::Expr::BreakExpr(b)
|
||||||
if (depth == 0 && b.lifetime().is_none()) || eq_label(b.lifetime()) =>
|
if (depth == 0 && b.lifetime().is_none()) || eq_label(b.lifetime()) =>
|
||||||
{
|
{
|
||||||
cb(b);
|
cb(ast::Expr::BreakExpr(b));
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue