Skip to content

Remove all dbg in the selected range #12114

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

Closed
TonalidadeHidrica opened this issue Apr 29, 2022 · 2 comments · Fixed by #13629
Closed

Remove all dbg in the selected range #12114

TonalidadeHidrica opened this issue Apr 29, 2022 · 2 comments · Fixed by #13629
Assignees
Labels
A-assists C-feature Category: feature request

Comments

@TonalidadeHidrica
Copy link
Contributor

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.

@lnicola lnicola added A-assists C-feature Category: feature request labels Apr 29, 2022
@petr-tik
Copy link
Contributor

petr-tik commented Jul 21, 2022

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?

@Veykril
Copy link
Member

Veykril commented Jul 22, 2022

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

pub(crate) fn extract_function(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let range = ctx.selection_trimmed();
if range.is_empty() {
return None;
}
let node = ctx.covering_element();
if node.kind() == COMMENT {
cov_mark::hit!(extract_function_in_comment_is_not_applicable);
return None;
}
let node = match node {
syntax::NodeOrToken::Node(n) => n,
syntax::NodeOrToken::Token(t) => t.parent()?,
};
let body = extraction_target(&node, range)?;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-assists C-feature Category: feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants