internal: migrate extract_module to SyntaxEditor#21868
internal: migrate extract_module to SyntaxEditor#21868itang06 wants to merge 13 commits intorust-lang:masterfrom
Conversation
There was a problem hiding this comment.
Please migrate remaining make::* usages to SyntaxFactory APIs
| continue; | ||
| } | ||
|
|
||
| let mut editor = SyntaxEditor::new(body_item.syntax().clone()); |
There was a problem hiding this comment.
Is this new SyntaxEditor instance and .finish() call on it necessary? Couldn't it be done by passing the mutable reference of existing one from the assist entrance function as a parameter of this function instead?
There was a problem hiding this comment.
the items here are detached clone_subtree() nodes, so the editor from the entry point can't reach them. I can use SyntaxFactory::without_mappings() locally to get rid of the .clone_for_update() calls instead, does that work?
There was a problem hiding this comment.
Hmm, yeah, I guess it could be still uplifted to the root SyntaxEditor but that would require more involved refactoring, so I think this is fine as is for now
| }) | ||
| .collect(); | ||
| if !replacements.is_empty() { | ||
| let mut editor = SyntaxEditor::new(entry.syntax().clone()); |
| @@ -18,8 +18,10 @@ use syntax::{ | |||
| self, HasVisibility, | |||
| edit::{AstNodeEdit, IndentLevel}, | |||
| make, | |||
There was a problem hiding this comment.
Kindly replace use of make with SyntaxFactory
| let assoc_item_list = make::assoc_item_list(Some(assoc_items)).clone_for_update(); | ||
| let impl_ = impl_.reset_indent(); | ||
| ted::replace(impl_.get_or_create_assoc_item_list().syntax(), assoc_item_list.syntax()); | ||
| let impl_detached = ast::Impl::cast(impl_.syntax().clone_subtree()).unwrap(); |
|
|
||
| let (mut replacements, record_field_parents, impls) = | ||
| get_replacements_for_visibility_change(&mut self.body_items, false); | ||
| get_replacements_for_visibility_change(&mut self.body_items, true); |
There was a problem hiding this comment.
this was a workaround because of the local SyntaxEditor approach, was an incorrect change
|
|
||
| let mut editor = SyntaxEditor::new(body_item.syntax().clone()); | ||
| for target in insert_targets { | ||
| let pub_crate_vis = make::visibility_pub_crate().clone_for_update(); |
| Some(( | ||
| seg.syntax().parent()?, | ||
| make::path_from_text(&format!("{mod_name}::{seg}")) | ||
| .clone_for_update(), |
There was a problem hiding this comment.
i missed that this should use SyntaxFactory, will replace it
|
@itang06 What's the status of this? |
i addressed the unwrap issue. waiting for ShoyuVanilla's response to my question about using |
11ff3da to
fbf2dfa
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
fbf2dfa to
a9d2246
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
| .entry(use_.syntax().text_range().start()) | ||
| .or_insert_with(|| use_.clone_subtree().clone_for_update()); | ||
| for seg in use_ | ||
| .or_insert_with(|| use_.clone_subtree()); |
There was a problem hiding this comment.
remove clone_subtree
| let assoc_item_list = make::assoc_item_list(Some(assoc_items)).clone_for_update(); | ||
| let impl_ = impl_.reset_indent(); | ||
| ted::replace(impl_.get_or_create_assoc_item_list().syntax(), assoc_item_list.syntax()); | ||
| let impl_detached = ast::Impl::cast(impl_.syntax().clone_subtree()).unwrap(); |
| ], | ||
| ); | ||
| } | ||
| *body_item = ast::Item::cast(editor.finish().new_root().clone_subtree()).unwrap(); |
There was a problem hiding this comment.
| *body_item = ast::Item::cast(editor.finish().new_root().clone_subtree()).unwrap(); | |
| *body_item = ast::Item::cast(editor.finish().new_root()).unwrap(); |
| for item in &mut self.body_items { | ||
| *item = ast::Item::cast(item.reset_indent().syntax().clone_subtree()).unwrap(); | ||
| } |
There was a problem hiding this comment.
No need to call clone_subtree here anymore. SyntaxEditor manages this internally
There was a problem hiding this comment.
i tried removing the clone_subtree() calls but found that 3 of the 4 calls require using the detached root returned by SyntaxEditor::new() instead of just dropping clone_subtree(). i think the 4th at line 436 has to stay because replacements is collected from body_items immediately after. is there something i'm missing or is there a different approach you had in mind?
Part of #18285
Migrates all
ted::calls incrates/ide-assists/src/handlers/extract_module.rsto the newSyntaxEditor/SyntaxFactoryabstractionChanges:
generate_module_def: replacedted::withSyntaxEditor/SyntaxFactoryexpand_and_group_usages_file_wise: replacedted::replacewithSyntaxEditorchange_visibility: replacedted::insert(viaadd_change_vishelper) withSyntaxEditor::insert_all; removes theadd_change_visfunction entirelyAI assistance was used for this contribution