diff options
| author | Prajwal S N <prajwalnadig21@gmail.com> | 2025-04-11 02:36:23 +0530 |
|---|---|---|
| committer | Prajwal S N <prajwalnadig21@gmail.com> | 2025-04-11 02:36:23 +0530 |
| commit | ec5363633340b6aa970523acb4f8200b2edba2fe (patch) | |
| tree | da1071804c2ccba5b2eaeb9ad5e788db6b3eb055 /src/tools/rust-analyzer/crates/syntax | |
| parent | e47bb175479c551c7dd828990f7ff7cb7ccce01f (diff) | |
| download | rust-ec5363633340b6aa970523acb4f8200b2edba2fe.tar.gz rust-ec5363633340b6aa970523acb4f8200b2edba2fe.zip | |
refactor: editor for `destructure_struct_binding`
Signed-off-by: Prajwal S N <prajwalnadig21@gmail.com>
Diffstat (limited to 'src/tools/rust-analyzer/crates/syntax')
| -rw-r--r-- | src/tools/rust-analyzer/crates/syntax/src/ast/make.rs | 4 | ||||
| -rw-r--r-- | src/tools/rust-analyzer/crates/syntax/src/ast/syntax_factory/constructors.rs | 21 |
2 files changed, 22 insertions, 3 deletions
diff --git a/src/tools/rust-analyzer/crates/syntax/src/ast/make.rs b/src/tools/rust-analyzer/crates/syntax/src/ast/make.rs index d5a5119ff68..eb9d65dbc6d 100644 --- a/src/tools/rust-analyzer/crates/syntax/src/ast/make.rs +++ b/src/tools/rust-analyzer/crates/syntax/src/ast/make.rs @@ -643,8 +643,8 @@ pub fn expr_method_call( ) -> ast::Expr { expr_from_text(&format!("{receiver}.{method}{arg_list}")) } -pub fn expr_macro_call(f: ast::Expr, arg_list: ast::ArgList) -> ast::Expr { - expr_from_text(&format!("{f}!{arg_list}")) +pub fn expr_macro(path: ast::Path, arg_list: ast::ArgList) -> ast::MacroExpr { + expr_from_text(&format!("{path}!{arg_list}")) } pub fn expr_ref(expr: ast::Expr, exclusive: bool) -> ast::Expr { expr_from_text(&if exclusive { format!("&mut {expr}") } else { format!("&{expr}") }) diff --git a/src/tools/rust-analyzer/crates/syntax/src/ast/syntax_factory/constructors.rs b/src/tools/rust-analyzer/crates/syntax/src/ast/syntax_factory/constructors.rs index f9dadf4b2c6..06ffed75b37 100644 --- a/src/tools/rust-analyzer/crates/syntax/src/ast/syntax_factory/constructors.rs +++ b/src/tools/rust-analyzer/crates/syntax/src/ast/syntax_factory/constructors.rs @@ -241,7 +241,7 @@ impl SyntaxFactory { ast } - pub fn record_pat_field(self, name_ref: ast::NameRef, pat: ast::Pat) -> ast::RecordPatField { + pub fn record_pat_field(&self, name_ref: ast::NameRef, pat: ast::Pat) -> ast::RecordPatField { let ast = make::record_pat_field(name_ref.clone(), pat.clone()).clone_for_update(); if let Some(mut mapping) = self.mappings() { @@ -290,6 +290,10 @@ impl SyntaxFactory { ast } + pub fn rest_pat(&self) -> ast::RestPat { + make::rest_pat().clone_for_update() + } + pub fn block_expr( &self, statements: impl IntoIterator<Item = ast::Stmt>, @@ -597,6 +601,21 @@ impl SyntaxFactory { ast } + pub fn expr_macro(&self, path: ast::Path, args: ast::ArgList) -> ast::MacroExpr { + let ast = make::expr_macro(path.clone(), args.clone()).clone_for_update(); + + if let Some(mut mapping) = self.mappings() { + let macro_call = ast.macro_call().unwrap(); + let mut builder = SyntaxMappingBuilder::new(macro_call.syntax().clone()); + builder.map_node(path.syntax().clone(), macro_call.path().unwrap().syntax().clone()); + builder + .map_node(args.syntax().clone(), macro_call.token_tree().unwrap().syntax().clone()); + builder.finish(&mut mapping); + } + + ast + } + pub fn match_arm( &self, pat: ast::Pat, |
