-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Migrate pull_assignment_up
assist to useSyntaxEditor
#20198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate pull_assignment_up
assist to useSyntaxEditor
#20198
Conversation
ted::replace(tgt.syntax(), assign_stmt.syntax().clone_for_update()); | ||
let new_tgt_root = editor.finish().new_root().clone(); | ||
let new_target_range = TextRange::new(target.start(), new_target_end); | ||
let new_tgt = find_node_at_range::<ast::Expr>(&new_tgt_root, new_target_range).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can simplify this with find_node_at_offset
with the offset target.start()
- because we trigger this assist only on if
and match
exprs and due to those tokens, there won't be any other child expr with the same offsets - and then we won't need new_target_range
calculation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And we can avoid this unwrap()
if we "pull up" this first half of twin-editor things outside of the closure - we can use SyntaxEditor::new
without edit
- though I don't think that's quite necessary 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And we can avoid this unwrap() if we "pull up" this first half of twin-editor things outside of the closure - we
can use SyntaxEditor::new without edit - though I don't think that's quite necessary 😅
Hmikihiro#4
I tried refactoring as suggested, though I’m not sure if the result is much cleaner overall.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggested avoiding unwrap()
because unwrap makes people a little bit nervous, not because it would be much cleaner 😅 Anyway, I think both are good and it's up to your choice 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I choice to avoid unwrap()
1b4bfba
to
11fc5da
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍
Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>
11fc5da
to
c6ce2ab
Compare
Oh, I have merge permission now |
part of #15710 and #18285