mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
Adds "replace with guarded return" assist
This commit is contained in:
parent
6b9bd7bdd2
commit
fb215dc192
4 changed files with 314 additions and 0 deletions
|
@ -128,6 +128,14 @@ pub fn where_clause(preds: impl Iterator<Item = ast::WherePred>) -> ast::WhereCl
|
|||
}
|
||||
}
|
||||
|
||||
pub fn if_expression(condition: &ast::Expr, statement: &str) -> ast::IfExpr {
|
||||
return ast_from_text(&format!(
|
||||
"fn f() {{ if !{} {{\n {}\n}}\n}}",
|
||||
condition.syntax().text(),
|
||||
statement
|
||||
));
|
||||
}
|
||||
|
||||
fn ast_from_text<N: AstNode>(text: &str) -> N {
|
||||
let parse = SourceFile::parse(text);
|
||||
let res = parse.tree().syntax().descendants().find_map(N::cast).unwrap();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue