mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-19 19:44:31 +00:00
refactor: improve macro handling in navigation for control-flow kws
This commit is contained in:
parent
f87220e22a
commit
9fa0543504
2 changed files with 47 additions and 13 deletions
|
|
@ -334,8 +334,10 @@ pub(crate) fn highlight_branches(
|
|||
match token.kind() {
|
||||
T![match] => {
|
||||
for token in sema.descend_into_macros(token.clone()) {
|
||||
let Some(match_expr) =
|
||||
sema.token_ancestors_with_macros(token).find_map(ast::MatchExpr::cast)
|
||||
let Some(match_expr) = sema
|
||||
.token_ancestors_with_macros(token)
|
||||
.take_while(|node| !ast::MacroCall::can_cast(node.kind()))
|
||||
.find_map(ast::MatchExpr::cast)
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
|
|
@ -355,11 +357,14 @@ pub(crate) fn highlight_branches(
|
|||
}
|
||||
T![=>] => {
|
||||
for token in sema.descend_into_macros(token.clone()) {
|
||||
let Some(arm) =
|
||||
sema.token_ancestors_with_macros(token).find_map(ast::MatchArm::cast)
|
||||
let Some(arm) = sema
|
||||
.token_ancestors_with_macros(token)
|
||||
.take_while(|node| !ast::MacroCall::can_cast(node.kind()))
|
||||
.find_map(ast::MatchArm::cast)
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
|
||||
let file_id = sema.hir_file_for(arm.syntax());
|
||||
let range = arm.fat_arrow_token().map(|token| token.text_range());
|
||||
push_to_highlights(file_id, range, &mut highlights);
|
||||
|
|
@ -368,9 +373,11 @@ pub(crate) fn highlight_branches(
|
|||
}
|
||||
}
|
||||
T![if] => {
|
||||
for tok in sema.descend_into_macros(token.clone()) {
|
||||
let Some(if_expr) =
|
||||
sema.token_ancestors_with_macros(tok).find_map(ast::IfExpr::cast)
|
||||
for token in sema.descend_into_macros(token.clone()) {
|
||||
let Some(if_expr) = sema
|
||||
.token_ancestors_with_macros(token)
|
||||
.take_while(|node| !ast::MacroCall::can_cast(node.kind()))
|
||||
.find_map(ast::IfExpr::cast)
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
|
|
@ -2481,6 +2488,27 @@ fn main() {
|
|||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn match_in_macro() {
|
||||
// We should not highlight the outer `match` expression.
|
||||
check(
|
||||
r#"
|
||||
macro_rules! M {
|
||||
(match) => { 1 };
|
||||
}
|
||||
|
||||
fn main() {
|
||||
match Some(1) {
|
||||
Some(x) => x,
|
||||
None => {
|
||||
M!(match$0)
|
||||
}
|
||||
}
|
||||
}
|
||||
"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn labeled_block_tail_expr() {
|
||||
check(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue