mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-27 10:17:15 +00:00
Migrate pull_assignment_up assist to SyntaxEditor
Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>
This commit is contained in:
parent
9a1fc3cdb8
commit
c6ce2abd47
4 changed files with 57 additions and 25 deletions
|
|
@ -680,7 +680,7 @@ pub fn expr_tuple(elements: impl IntoIterator<Item = ast::Expr>) -> ast::TupleEx
|
|||
let expr = elements.into_iter().format(", ");
|
||||
expr_from_text(&format!("({expr})"))
|
||||
}
|
||||
pub fn expr_assignment(lhs: ast::Expr, rhs: ast::Expr) -> ast::Expr {
|
||||
pub fn expr_assignment(lhs: ast::Expr, rhs: ast::Expr) -> ast::BinExpr {
|
||||
expr_from_text(&format!("{lhs} = {rhs}"))
|
||||
}
|
||||
fn expr_from_text<E: Into<ast::Expr> + AstNode>(text: &str) -> E {
|
||||
|
|
|
|||
|
|
@ -440,6 +440,19 @@ impl SyntaxFactory {
|
|||
ast
|
||||
}
|
||||
|
||||
pub fn expr_assignment(&self, lhs: ast::Expr, rhs: ast::Expr) -> ast::BinExpr {
|
||||
let ast = make::expr_assignment(lhs.clone(), rhs.clone()).clone_for_update();
|
||||
|
||||
if let Some(mut mapping) = self.mappings() {
|
||||
let mut builder = SyntaxMappingBuilder::new(ast.syntax().clone());
|
||||
builder.map_node(lhs.syntax().clone(), ast.lhs().unwrap().syntax().clone());
|
||||
builder.map_node(rhs.syntax().clone(), ast.rhs().unwrap().syntax().clone());
|
||||
builder.finish(&mut mapping);
|
||||
}
|
||||
|
||||
ast
|
||||
}
|
||||
|
||||
pub fn expr_bin(&self, lhs: ast::Expr, op: ast::BinaryOp, rhs: ast::Expr) -> ast::BinExpr {
|
||||
let ast::Expr::BinExpr(ast) =
|
||||
make::expr_bin_op(lhs.clone(), op, rhs.clone()).clone_for_update()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue