Migrate generate function to SyntaxEditor#22159
Open
Shourya742 wants to merge 1 commit intorust-lang:masterfrom
Open
Migrate generate function to SyntaxEditor#22159Shourya742 wants to merge 1 commit intorust-lang:masterfrom
Shourya742 wants to merge 1 commit intorust-lang:masterfrom
Conversation
ChayimFriedman2
requested changes
Apr 24, 2026
| let target = function_builder.target.clone(); | ||
| let edition = function_builder.target_edition; | ||
| let func = function_builder.render(ctx.config.snippet_cap, edit); | ||
| let cap = ctx.config.snippet_cap; |
Contributor
There was a problem hiding this comment.
Suggested change
| let cap = ctx.config.snippet_cap; | |
| let snippet_cap = ctx.config.snippet_cap; |
cap is two generic.
| let current_module = ctx.sema.scope(call.syntax())?.module(); | ||
| let visibility = calculate_necessary_visibility(current_module, target_module, ctx); | ||
| let fn_name = make::name(fn_name); | ||
| let make = SyntaxFactory::without_mappings(); |
Contributor
There was a problem hiding this comment.
Why don't you pass a SyntaxFactory to this function? I'll repeat again that once nodes will have a lifetime stuff like this will be impossible.
Comment on lines
+623
to
+648
| // FIXME: adt may have generic params. | ||
| let fn_ = function_builder.render().indent(IndentLevel(1)); | ||
| let impl_ = make.impl_( | ||
| None, | ||
| None, | ||
| None, | ||
| name.into(), | ||
| None, | ||
| Some(make.assoc_item_list([fn_.into()])), | ||
| ); | ||
| let impl_ = impl_.indent(indent); | ||
| if let Some(cap) = cap | ||
| && let Some(fn_) = impl_.syntax().descendants().find_map(ast::Fn::cast) | ||
| { | ||
| let annotation = edit.make_placeholder_snippet(cap); | ||
| if function_builder.should_focus_return_type | ||
| && let Some(ret_type) = fn_.ret_type() | ||
| { | ||
| editor.add_annotation(ret_type.syntax(), annotation); | ||
| } else if let Some(tail_expr) = fn_.body().and_then(|body| body.tail_expr()) { | ||
| editor.add_annotation(tail_expr.syntax(), annotation); | ||
| } | ||
| } | ||
|
|
||
| ted::insert_all(position, vec![leading_ws.into(), impl_.syntax().clone().into()]); | ||
| editor.insert_all(position, vec![leading_ws.into(), impl_.syntax().clone().into()]); | ||
| edit.add_file_edits(file, editor); |
Contributor
There was a problem hiding this comment.
Potential for code sharing here?
Comment on lines
+675
to
+688
| let func = function_builder.render().indent(indent); | ||
| if let Some(cap) = cap { | ||
| let annotation = edit.make_placeholder_snippet(cap); | ||
| if function_builder.should_focus_return_type | ||
| && let Some(ret_type) = func.ret_type() | ||
| { | ||
| editor.add_annotation(ret_type.syntax(), annotation); | ||
| } else if let Some(tail_expr) = func.body().and_then(|body| body.tail_expr()) { | ||
| editor.add_annotation(tail_expr.syntax(), annotation); | ||
| } | ||
| } | ||
|
|
||
| ted::insert_all_raw( | ||
| position, | ||
| vec![leading_ws.into(), func.syntax().clone().into()], | ||
| ); | ||
| editor.insert_all(position, vec![leading_ws.into(), func.syntax().clone().into()]); | ||
| edit.add_file_edits(file, editor); |
Contributor
There was a problem hiding this comment.
And here too.
Comment on lines
+705
to
+714
| if let Some(cap) = cap { | ||
| let annotation = edit.make_placeholder_snippet(cap); | ||
| if function_builder.should_focus_return_type | ||
| && let Some(ret_type) = func.ret_type() | ||
| { | ||
| editor.add_annotation(ret_type.syntax(), annotation); | ||
| } else if let Some(tail_expr) = func.body().and_then(|body| body.tail_expr()) { | ||
| editor.add_annotation(tail_expr.syntax(), annotation); | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
Here too.
Comment on lines
+728
to
+737
| if let Some(cap) = cap { | ||
| let annotation = edit.make_placeholder_snippet(cap); | ||
| if function_builder.should_focus_return_type | ||
| && let Some(ret_type) = func.ret_type() | ||
| { | ||
| editor.add_annotation(ret_type.syntax(), annotation); | ||
| } else if let Some(tail_expr) = func.body().and_then(|body| body.tail_expr()) { | ||
| editor.add_annotation(tail_expr.syntax(), annotation); | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
Here too.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
part of #15710 and #18285