2020-08-12 11:26:51 -05:00
|
|
|
use syntax::{
|
2021-03-27 04:10:20 -05:00
|
|
|
ast::{self, AstNode, AstToken},
|
2021-01-10 09:40:52 -06:00
|
|
|
match_ast, SyntaxElement, TextRange, TextSize, T,
|
2019-02-07 12:00:58 -06:00
|
|
|
};
|
|
|
|
|
2020-06-28 17:36:05 -05:00
|
|
|
use crate::{AssistContext, AssistId, AssistKind, Assists};
|
2019-10-27 04:22:53 -05:00
|
|
|
|
|
|
|
// Assist: remove_dbg
|
|
|
|
//
|
|
|
|
// Removes `dbg!()` macro call.
|
|
|
|
//
|
|
|
|
// ```
|
|
|
|
// fn main() {
|
2021-01-06 14:15:48 -06:00
|
|
|
// $0dbg!(92);
|
2019-10-27 04:22:53 -05:00
|
|
|
// }
|
|
|
|
// ```
|
|
|
|
// ->
|
|
|
|
// ```
|
|
|
|
// fn main() {
|
|
|
|
// 92;
|
|
|
|
// }
|
|
|
|
// ```
|
2020-05-06 11:45:35 -05:00
|
|
|
pub(crate) fn remove_dbg(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
|
2019-10-27 03:48:40 -05:00
|
|
|
let macro_call = ctx.find_node_at_offset::<ast::MacroCall>()?;
|
2020-09-10 06:14:24 -05:00
|
|
|
let new_contents = adjusted_macro_contents(¯o_call)?;
|
2019-02-07 12:00:58 -06:00
|
|
|
|
2021-03-27 04:10:20 -05:00
|
|
|
let macro_text_range = if new_contents.is_empty() {
|
|
|
|
let parent = macro_call.syntax().parent()?;
|
|
|
|
|
|
|
|
let start = parent
|
|
|
|
.prev_sibling_or_token()
|
|
|
|
.and_then(|el| {
|
|
|
|
Some(el.into_token().and_then(ast::Whitespace::cast)?.syntax().text_range().start())
|
|
|
|
})
|
|
|
|
.unwrap_or(parent.text_range().start());
|
|
|
|
let end = parent.text_range().end();
|
|
|
|
|
|
|
|
TextRange::new(start, end)
|
2020-07-29 16:12:53 -05:00
|
|
|
} else {
|
2021-03-27 04:10:20 -05:00
|
|
|
macro_call.syntax().text_range()
|
|
|
|
};
|
|
|
|
|
|
|
|
let macro_end = match macro_call.semicolon_token() {
|
|
|
|
Some(_) => macro_text_range.end() - TextSize::of(';'),
|
|
|
|
None => macro_text_range.end(),
|
2020-07-27 16:17:15 -05:00
|
|
|
};
|
2019-02-07 12:00:58 -06:00
|
|
|
|
2020-09-10 06:14:24 -05:00
|
|
|
acc.add(
|
|
|
|
AssistId("remove_dbg", AssistKind::Refactor),
|
|
|
|
"Remove dbg!()",
|
|
|
|
macro_text_range,
|
|
|
|
|builder| {
|
|
|
|
builder.replace(TextRange::new(macro_text_range.start(), macro_end), new_contents);
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
2019-02-07 12:00:58 -06:00
|
|
|
|
2020-09-10 06:14:24 -05:00
|
|
|
fn adjusted_macro_contents(macro_call: &ast::MacroCall) -> Option<String> {
|
|
|
|
let contents = get_valid_macrocall_contents(¯o_call, "dbg")?;
|
|
|
|
let macro_text_with_brackets = macro_call.token_tree()?.syntax().text();
|
2020-09-11 14:16:22 -05:00
|
|
|
let macro_text_in_brackets = macro_text_with_brackets.slice(TextRange::new(
|
|
|
|
TextSize::of('('),
|
|
|
|
macro_text_with_brackets.len() - TextSize::of(')'),
|
|
|
|
));
|
|
|
|
|
2020-11-20 09:44:52 -06:00
|
|
|
Some(
|
|
|
|
if !is_leaf_or_control_flow_expr(macro_call)
|
|
|
|
&& needs_parentheses_around_macro_contents(contents)
|
|
|
|
{
|
|
|
|
format!("({})", macro_text_in_brackets)
|
|
|
|
} else {
|
|
|
|
macro_text_in_brackets.to_string()
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_leaf_or_control_flow_expr(macro_call: &ast::MacroCall) -> bool {
|
|
|
|
macro_call.syntax().next_sibling().is_none()
|
|
|
|
|| match macro_call.syntax().parent() {
|
|
|
|
Some(parent) => match_ast! {
|
|
|
|
match parent {
|
|
|
|
ast::Condition(_it) => true,
|
|
|
|
ast::MatchExpr(_it) => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
None => false,
|
|
|
|
}
|
2019-02-07 12:00:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Verifies that the given macro_call actually matches the given name
|
2020-09-10 06:14:24 -05:00
|
|
|
/// and contains proper ending tokens, then returns the contents between the ending tokens
|
|
|
|
fn get_valid_macrocall_contents(
|
|
|
|
macro_call: &ast::MacroCall,
|
|
|
|
macro_name: &str,
|
|
|
|
) -> Option<Vec<SyntaxElement>> {
|
2019-02-07 12:00:58 -06:00
|
|
|
let path = macro_call.path()?;
|
|
|
|
let name_ref = path.segment()?.name_ref()?;
|
|
|
|
|
2019-02-11 10:18:27 -06:00
|
|
|
// Make sure it is actually a dbg-macro call, dbg followed by !
|
2019-03-30 05:25:53 -05:00
|
|
|
let excl = path.syntax().next_sibling_or_token()?;
|
2019-05-15 07:35:47 -05:00
|
|
|
if name_ref.text() != macro_name || excl.kind() != T![!] {
|
2019-02-07 12:00:58 -06:00
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2020-09-10 06:14:24 -05:00
|
|
|
let mut children_with_tokens = macro_call.token_tree()?.syntax().children_with_tokens();
|
|
|
|
let first_child = children_with_tokens.next()?;
|
|
|
|
let mut contents_between_brackets = children_with_tokens.collect::<Vec<_>>();
|
|
|
|
let last_child = contents_between_brackets.pop()?;
|
2019-02-07 12:00:58 -06:00
|
|
|
|
2021-03-26 09:15:26 -05:00
|
|
|
match (first_child.kind(), last_child.kind()) {
|
|
|
|
(T!['('], T![')']) | (T!['['], T![']']) | (T!['{'], T!['}']) => {
|
|
|
|
Some(contents_between_brackets)
|
2020-09-10 06:14:24 -05:00
|
|
|
}
|
2021-03-26 09:15:26 -05:00
|
|
|
_ => None,
|
2019-02-07 12:00:58 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-10 06:14:24 -05:00
|
|
|
fn needs_parentheses_around_macro_contents(macro_contents: Vec<SyntaxElement>) -> bool {
|
|
|
|
if macro_contents.len() < 2 {
|
|
|
|
return false;
|
|
|
|
}
|
2020-10-25 09:36:02 -05:00
|
|
|
let mut macro_contents = macro_contents.into_iter().peekable();
|
2020-09-10 06:14:24 -05:00
|
|
|
let mut unpaired_brackets_in_contents = Vec::new();
|
2020-10-25 09:36:02 -05:00
|
|
|
while let Some(element) = macro_contents.next() {
|
2020-09-10 06:14:24 -05:00
|
|
|
match element.kind() {
|
2020-09-11 14:16:22 -05:00
|
|
|
T!['('] | T!['['] | T!['{'] => unpaired_brackets_in_contents.push(element),
|
2020-09-10 06:14:24 -05:00
|
|
|
T![')'] => {
|
|
|
|
if !matches!(unpaired_brackets_in_contents.pop(), Some(correct_bracket) if correct_bracket.kind() == T!['('])
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
T![']'] => {
|
|
|
|
if !matches!(unpaired_brackets_in_contents.pop(), Some(correct_bracket) if correct_bracket.kind() == T!['['])
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
T!['}'] => {
|
|
|
|
if !matches!(unpaired_brackets_in_contents.pop(), Some(correct_bracket) if correct_bracket.kind() == T!['{'])
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2020-09-11 14:16:22 -05:00
|
|
|
symbol_kind => {
|
|
|
|
let symbol_not_in_bracket = unpaired_brackets_in_contents.is_empty();
|
2020-10-06 06:21:22 -05:00
|
|
|
if symbol_not_in_bracket
|
2021-01-10 09:40:52 -06:00
|
|
|
&& symbol_kind != T![:] // paths
|
|
|
|
&& (symbol_kind != T![.] // field/method access
|
2020-10-25 09:36:02 -05:00
|
|
|
|| macro_contents // range expressions consist of two SyntaxKind::Dot in macro invocations
|
|
|
|
.peek()
|
2021-01-10 09:40:52 -06:00
|
|
|
.map(|element| element.kind() == T![.])
|
2020-10-25 09:36:02 -05:00
|
|
|
.unwrap_or(false))
|
2021-01-10 09:40:52 -06:00
|
|
|
&& symbol_kind != T![?] // try operator
|
|
|
|
&& (symbol_kind.is_punct() || symbol_kind == T![as])
|
2020-10-06 06:21:22 -05:00
|
|
|
{
|
2020-09-11 14:16:22 -05:00
|
|
|
return true;
|
2020-09-10 06:14:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
!unpaired_brackets_in_contents.is_empty()
|
|
|
|
}
|
|
|
|
|
2019-02-07 12:00:58 -06:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2020-05-06 03:16:55 -05:00
|
|
|
use crate::tests::{check_assist, check_assist_not_applicable, check_assist_target};
|
2019-02-07 12:00:58 -06:00
|
|
|
|
2020-08-19 11:44:33 -05:00
|
|
|
use super::*;
|
|
|
|
|
2019-02-07 12:00:58 -06:00
|
|
|
#[test]
|
|
|
|
fn test_remove_dbg() {
|
2021-01-06 14:15:48 -06:00
|
|
|
check_assist(remove_dbg, "$0dbg!(1 + 1)", "1 + 1");
|
2019-02-07 12:00:58 -06:00
|
|
|
|
2021-01-06 14:15:48 -06:00
|
|
|
check_assist(remove_dbg, "dbg!$0((1 + 1))", "(1 + 1)");
|
2019-02-07 12:00:58 -06:00
|
|
|
|
2021-01-06 14:15:48 -06:00
|
|
|
check_assist(remove_dbg, "dbg!(1 $0+ 1)", "1 + 1");
|
2019-02-07 12:00:58 -06:00
|
|
|
|
2021-01-06 14:15:48 -06:00
|
|
|
check_assist(remove_dbg, "let _ = $0dbg!(1 + 1)", "let _ = 1 + 1");
|
2019-02-07 12:00:58 -06:00
|
|
|
|
|
|
|
check_assist(
|
|
|
|
remove_dbg,
|
|
|
|
"
|
|
|
|
fn foo(n: usize) {
|
2021-01-06 14:15:48 -06:00
|
|
|
if let Some(_) = dbg!(n.$0checked_sub(4)) {
|
2019-02-07 12:00:58 -06:00
|
|
|
// ...
|
|
|
|
}
|
|
|
|
}
|
|
|
|
",
|
|
|
|
"
|
|
|
|
fn foo(n: usize) {
|
2020-05-20 16:14:31 -05:00
|
|
|
if let Some(_) = n.checked_sub(4) {
|
2019-02-07 12:00:58 -06:00
|
|
|
// ...
|
|
|
|
}
|
|
|
|
}
|
|
|
|
",
|
|
|
|
);
|
2020-10-06 06:21:22 -05:00
|
|
|
|
2021-01-06 14:15:48 -06:00
|
|
|
check_assist(remove_dbg, "$0dbg!(Foo::foo_test()).bar()", "Foo::foo_test().bar()");
|
2019-02-07 12:00:58 -06:00
|
|
|
}
|
2020-07-27 15:28:41 -05:00
|
|
|
|
2019-02-07 12:00:58 -06:00
|
|
|
#[test]
|
|
|
|
fn test_remove_dbg_with_brackets_and_braces() {
|
2021-01-06 14:15:48 -06:00
|
|
|
check_assist(remove_dbg, "dbg![$01 + 1]", "1 + 1");
|
|
|
|
check_assist(remove_dbg, "dbg!{$01 + 1}", "1 + 1");
|
2019-02-07 12:00:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_remove_dbg_not_applicable() {
|
2021-01-06 14:15:48 -06:00
|
|
|
check_assist_not_applicable(remove_dbg, "$0vec![1, 2, 3]");
|
|
|
|
check_assist_not_applicable(remove_dbg, "$0dbg(5, 6, 7)");
|
|
|
|
check_assist_not_applicable(remove_dbg, "$0dbg!(5, 6, 7");
|
2019-02-07 12:00:58 -06:00
|
|
|
}
|
2019-02-08 17:34:05 -06:00
|
|
|
|
|
|
|
#[test]
|
2020-07-27 15:28:41 -05:00
|
|
|
fn test_remove_dbg_target() {
|
2019-02-08 17:34:05 -06:00
|
|
|
check_assist_target(
|
|
|
|
remove_dbg,
|
|
|
|
"
|
|
|
|
fn foo(n: usize) {
|
2021-01-06 14:15:48 -06:00
|
|
|
if let Some(_) = dbg!(n.$0checked_sub(4)) {
|
2019-02-08 17:34:05 -06:00
|
|
|
// ...
|
|
|
|
}
|
|
|
|
}
|
|
|
|
",
|
|
|
|
"dbg!(n.checked_sub(4))",
|
|
|
|
);
|
|
|
|
}
|
2020-07-24 12:57:40 -05:00
|
|
|
|
|
|
|
#[test]
|
2020-07-27 15:28:41 -05:00
|
|
|
fn test_remove_dbg_keep_semicolon() {
|
2020-07-24 12:57:40 -05:00
|
|
|
// https://github.com/rust-analyzer/rust-analyzer/issues/5129#issuecomment-651399779
|
|
|
|
// not quite though
|
2020-07-27 16:17:15 -05:00
|
|
|
// adding a comment at the end of the line makes
|
|
|
|
// the ast::MacroCall to include the semicolon at the end
|
2020-07-29 16:12:53 -05:00
|
|
|
check_assist(
|
|
|
|
remove_dbg,
|
2021-01-06 14:15:48 -06:00
|
|
|
r#"let res = $0dbg!(1 * 20); // needless comment"#,
|
2020-07-29 16:12:53 -05:00
|
|
|
r#"let res = 1 * 20; // needless comment"#,
|
|
|
|
);
|
2020-07-24 12:57:40 -05:00
|
|
|
}
|
|
|
|
|
2020-09-10 06:14:24 -05:00
|
|
|
#[test]
|
|
|
|
fn remove_dbg_from_non_leaf_simple_expression() {
|
|
|
|
check_assist(
|
|
|
|
remove_dbg,
|
|
|
|
"
|
|
|
|
fn main() {
|
|
|
|
let mut a = 1;
|
2021-01-06 14:15:48 -06:00
|
|
|
while dbg!$0(a) < 10000 {
|
2020-09-10 06:14:24 -05:00
|
|
|
a += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
",
|
|
|
|
"
|
|
|
|
fn main() {
|
|
|
|
let mut a = 1;
|
|
|
|
while a < 10000 {
|
|
|
|
a += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-07-24 12:57:40 -05:00
|
|
|
#[test]
|
2020-07-27 15:28:41 -05:00
|
|
|
fn test_remove_dbg_keep_expression() {
|
2020-07-29 16:12:53 -05:00
|
|
|
check_assist(
|
|
|
|
remove_dbg,
|
2021-01-06 14:15:48 -06:00
|
|
|
r#"let res = $0dbg!(a + b).foo();"#,
|
2020-07-29 16:12:53 -05:00
|
|
|
r#"let res = (a + b).foo();"#,
|
|
|
|
);
|
2020-09-10 16:20:13 -05:00
|
|
|
|
2021-01-06 14:15:48 -06:00
|
|
|
check_assist(remove_dbg, r#"let res = $0dbg!(2 + 2) * 5"#, r#"let res = (2 + 2) * 5"#);
|
|
|
|
check_assist(remove_dbg, r#"let res = $0dbg![2 + 2] * 5"#, r#"let res = (2 + 2) * 5"#);
|
2020-07-24 12:57:40 -05:00
|
|
|
}
|
2020-07-27 15:28:41 -05:00
|
|
|
|
2020-10-25 08:27:32 -05:00
|
|
|
#[test]
|
|
|
|
fn test_remove_dbg_method_chaining() {
|
|
|
|
check_assist(
|
|
|
|
remove_dbg,
|
2021-01-06 14:15:48 -06:00
|
|
|
r#"let res = $0dbg!(foo().bar()).baz();"#,
|
2020-10-25 08:27:32 -05:00
|
|
|
r#"let res = foo().bar().baz();"#,
|
|
|
|
);
|
|
|
|
check_assist(
|
|
|
|
remove_dbg,
|
2021-01-06 14:15:48 -06:00
|
|
|
r#"let res = $0dbg!(foo.bar()).baz();"#,
|
2020-10-25 08:27:32 -05:00
|
|
|
r#"let res = foo.bar().baz();"#,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_remove_dbg_field_chaining() {
|
2021-01-06 14:15:48 -06:00
|
|
|
check_assist(remove_dbg, r#"let res = $0dbg!(foo.bar).baz;"#, r#"let res = foo.bar.baz;"#);
|
2020-10-25 08:27:32 -05:00
|
|
|
}
|
|
|
|
|
2020-07-27 15:28:41 -05:00
|
|
|
#[test]
|
|
|
|
fn test_remove_dbg_from_inside_fn() {
|
2020-07-29 16:12:53 -05:00
|
|
|
check_assist_target(
|
|
|
|
remove_dbg,
|
|
|
|
r#"
|
2020-07-27 15:28:41 -05:00
|
|
|
fn square(x: u32) -> u32 {
|
|
|
|
x * x
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2021-01-06 14:15:48 -06:00
|
|
|
let x = square(dbg$0!(5 + 10));
|
2020-07-29 16:12:53 -05:00
|
|
|
println!("{}", x);
|
|
|
|
}"#,
|
|
|
|
"dbg!(5 + 10)",
|
|
|
|
);
|
2020-07-27 15:28:41 -05:00
|
|
|
|
2020-07-29 16:12:53 -05:00
|
|
|
check_assist(
|
|
|
|
remove_dbg,
|
|
|
|
r#"
|
|
|
|
fn square(x: u32) -> u32 {
|
|
|
|
x * x
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2021-01-06 14:15:48 -06:00
|
|
|
let x = square(dbg$0!(5 + 10));
|
2020-07-29 16:12:53 -05:00
|
|
|
println!("{}", x);
|
|
|
|
}"#,
|
|
|
|
r#"
|
2020-07-27 15:28:41 -05:00
|
|
|
fn square(x: u32) -> u32 {
|
|
|
|
x * x
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let x = square(5 + 10);
|
2020-07-29 16:12:53 -05:00
|
|
|
println!("{}", x);
|
|
|
|
}"#,
|
|
|
|
);
|
2020-07-27 15:28:41 -05:00
|
|
|
}
|
2020-10-25 09:12:21 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_remove_dbg_try_expr() {
|
|
|
|
check_assist(
|
|
|
|
remove_dbg,
|
2021-01-06 14:15:48 -06:00
|
|
|
r#"let res = $0dbg!(result?).foo();"#,
|
2020-10-25 09:12:21 -05:00
|
|
|
r#"let res = result?.foo();"#,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_remove_dbg_await_expr() {
|
|
|
|
check_assist(
|
|
|
|
remove_dbg,
|
2021-01-06 14:15:48 -06:00
|
|
|
r#"let res = $0dbg!(fut.await).foo();"#,
|
2020-10-25 09:12:21 -05:00
|
|
|
r#"let res = fut.await.foo();"#,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_remove_dbg_as_cast() {
|
|
|
|
check_assist(
|
|
|
|
remove_dbg,
|
2021-01-06 14:15:48 -06:00
|
|
|
r#"let res = $0dbg!(3 as usize).foo();"#,
|
2020-10-25 09:12:21 -05:00
|
|
|
r#"let res = (3 as usize).foo();"#,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_remove_dbg_index_expr() {
|
|
|
|
check_assist(
|
|
|
|
remove_dbg,
|
2021-01-06 14:15:48 -06:00
|
|
|
r#"let res = $0dbg!(array[3]).foo();"#,
|
2020-10-25 09:12:21 -05:00
|
|
|
r#"let res = array[3].foo();"#,
|
|
|
|
);
|
|
|
|
check_assist(
|
|
|
|
remove_dbg,
|
2021-01-06 14:15:48 -06:00
|
|
|
r#"let res = $0dbg!(tuple.3).foo();"#,
|
2020-10-25 09:12:21 -05:00
|
|
|
r#"let res = tuple.3.foo();"#,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_remove_dbg_range_expr() {
|
|
|
|
check_assist(
|
|
|
|
remove_dbg,
|
2021-01-06 14:15:48 -06:00
|
|
|
r#"let res = $0dbg!(foo..bar).foo();"#,
|
2020-10-25 09:12:21 -05:00
|
|
|
r#"let res = (foo..bar).foo();"#,
|
|
|
|
);
|
|
|
|
check_assist(
|
|
|
|
remove_dbg,
|
2021-01-06 14:15:48 -06:00
|
|
|
r#"let res = $0dbg!(foo..=bar).foo();"#,
|
2020-10-25 09:12:21 -05:00
|
|
|
r#"let res = (foo..=bar).foo();"#,
|
|
|
|
);
|
|
|
|
}
|
2020-11-20 09:44:52 -06:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_remove_dbg_followed_by_block() {
|
|
|
|
check_assist(
|
|
|
|
remove_dbg,
|
|
|
|
r#"fn foo() {
|
2021-01-06 14:15:48 -06:00
|
|
|
if $0dbg!(x || y) {}
|
2020-11-20 09:44:52 -06:00
|
|
|
}"#,
|
|
|
|
r#"fn foo() {
|
|
|
|
if x || y {}
|
|
|
|
}"#,
|
|
|
|
);
|
|
|
|
check_assist(
|
|
|
|
remove_dbg,
|
|
|
|
r#"fn foo() {
|
2021-01-06 14:15:48 -06:00
|
|
|
while let foo = $0dbg!(&x) {}
|
2020-11-20 09:44:52 -06:00
|
|
|
}"#,
|
|
|
|
r#"fn foo() {
|
|
|
|
while let foo = &x {}
|
|
|
|
}"#,
|
|
|
|
);
|
|
|
|
check_assist(
|
|
|
|
remove_dbg,
|
|
|
|
r#"fn foo() {
|
2021-01-06 14:15:48 -06:00
|
|
|
if let foo = $0dbg!(&x) {}
|
2020-11-20 09:44:52 -06:00
|
|
|
}"#,
|
|
|
|
r#"fn foo() {
|
|
|
|
if let foo = &x {}
|
|
|
|
}"#,
|
|
|
|
);
|
|
|
|
check_assist(
|
|
|
|
remove_dbg,
|
|
|
|
r#"fn foo() {
|
2021-01-06 14:15:48 -06:00
|
|
|
match $0dbg!(&x) {}
|
2020-11-20 09:44:52 -06:00
|
|
|
}"#,
|
|
|
|
r#"fn foo() {
|
|
|
|
match &x {}
|
|
|
|
}"#,
|
|
|
|
);
|
|
|
|
}
|
2021-03-26 09:15:26 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_remove_empty_dbg() {
|
2021-03-27 04:10:20 -05:00
|
|
|
check_assist(remove_dbg, r#"fn foo() { $0dbg!(); }"#, r#"fn foo() { }"#);
|
|
|
|
check_assist(
|
|
|
|
remove_dbg,
|
|
|
|
r#"fn foo() {
|
|
|
|
$0dbg!();
|
|
|
|
}"#,
|
|
|
|
r#"fn foo() {
|
|
|
|
}"#,
|
|
|
|
);
|
2021-03-26 09:15:26 -05:00
|
|
|
}
|
2019-02-07 12:00:58 -06:00
|
|
|
}
|