mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-28 22:13:39 +00:00
fix: handle attributes when typing curly bracket
This commit is contained in:
parent
5ecace48f6
commit
109344cfb7
1 changed files with 30 additions and 3 deletions
|
@ -175,9 +175,21 @@ fn on_opening_bracket_typed(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it's a statement in a block, we don't know how many statements should be included
|
if let Some(parent) = expr.syntax().parent().and_then(ast::Expr::cast) {
|
||||||
if ast::ExprStmt::can_cast(expr.syntax().parent()?.kind()) {
|
let mut node = expr.syntax().clone();
|
||||||
return None;
|
let all_prev_sib_attr = loop {
|
||||||
|
match node.prev_sibling() {
|
||||||
|
Some(sib) if sib.kind().is_trivia() || sib.kind() == SyntaxKind::ATTR => {
|
||||||
|
node = sib
|
||||||
|
}
|
||||||
|
Some(_) => break false,
|
||||||
|
None => break true,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
if all_prev_sib_attr {
|
||||||
|
expr = parent;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert the closing bracket right after the expression.
|
// Insert the closing bracket right after the expression.
|
||||||
|
@ -824,6 +836,21 @@ fn f() {
|
||||||
0 => {()},
|
0 => {()},
|
||||||
1 => (),
|
1 => (),
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
type_char(
|
||||||
|
'{',
|
||||||
|
r#"
|
||||||
|
fn main() {
|
||||||
|
#[allow(unreachable_code)]
|
||||||
|
$0g();
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
r#"
|
||||||
|
fn main() {
|
||||||
|
#[allow(unreachable_code)]
|
||||||
|
{g()};
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue