Remove all `dbg` in the selected range
We can remove a single dbg!(..) by moving the cursor on dbg, opening quick action and selecting "remove dbg". However, this is a bit troublesome when it comes to removing multiple dbgs. It would be nice if we can remove all dbgs in the selected range.
can i please get some guidance on how to tackle this @lnicola?
I was thinking about splitting the remove_dbg function into 2 functions like this
pub(crate) fn remove_dbg(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
match ctx.has_empty_selection() {
true => remove_dbg_at_point(acc, ctx),
false => remove_dbg_from_range(acc, ctx),
}
}
remove_dbg_at_point will keep the original implementation
remove_dbg_from_range will iterate over the nodes in the range and call remove_dbg_at_point on all dbg! nodes and present that as an AssistKind::RefactorRewrite
what do you think about this approach? If it sounds reasonable, what's the best way to iterate over the nodes in an arbitrary text range with smart exclusion (i.e. people might shift select text across function or method boundaries)?
if this doesn't sound as good, what would you recommend I do to tackle this?
The closest we have to that is probably the extract_function assist, but even that isn't too smart about the extraction range yet. Though in this case function boundaries don't really matter do they, shouldn't matter if you remove dbg from multiple functions at once.
So this part should give you some pointers on what to do here i think https://github.com/rust-lang/rust-analyzer/blob/84a6fac37ad61ff512993ee64b47deff9a52c560/crates/ide-assists/src/handlers/extract_function.rs#L63-L80