@@ -27,25 +27,26 @@ pub(crate) fn remove_dbg(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
27
27
return None ;
28
28
}
29
29
30
- let semicolon_on_end = macro_call. semicolon_token ( ) . is_some ( ) ;
31
30
let is_leaf = macro_call. syntax ( ) . next_sibling ( ) . is_none ( ) ;
32
31
33
- let macro_end = match semicolon_on_end {
34
- true => macro_call. syntax ( ) . text_range ( ) . end ( ) - TextSize :: of ( ';' ) ,
35
- false => macro_call. syntax ( ) . text_range ( ) . end ( ) ,
32
+ let macro_end = if macro_call. semicolon_token ( ) . is_some ( ) {
33
+ macro_call. syntax ( ) . text_range ( ) . end ( ) - TextSize :: of ( ';' )
34
+ } else {
35
+ macro_call. syntax ( ) . text_range ( ) . end ( )
36
36
} ;
37
37
38
38
// macro_range determines what will be deleted and replaced with macro_content
39
39
let macro_range = TextRange :: new ( macro_call. syntax ( ) . text_range ( ) . start ( ) , macro_end) ;
40
40
let paste_instead_of_dbg = {
41
41
let text = macro_call. token_tree ( ) ?. syntax ( ) . text ( ) ;
42
42
43
- // leafines determines if we should include the parenthesis or not
44
- let slice_index: TextRange = match is_leaf {
43
+ // leafiness determines if we should include the parenthesis or not
44
+ let slice_index: TextRange = if is_leaf {
45
45
// leaf means - we can extract the contents of the dbg! in text
46
- true => TextRange :: new ( TextSize :: of ( '(' ) , text. len ( ) - TextSize :: of ( ')' ) ) ,
46
+ TextRange :: new ( TextSize :: of ( '(' ) , text. len ( ) - TextSize :: of ( ')' ) )
47
+ } else {
47
48
// not leaf - means we should keep the parens
48
- false => TextRange :: new ( TextSize :: from ( 0 as u32 ) , text. len ( ) ) ,
49
+ TextRange :: up_to ( text. len ( ) )
49
50
} ;
50
51
text. slice ( slice_index) . to_string ( )
51
52
} ;
@@ -147,45 +148,58 @@ fn foo(n: usize) {
147
148
// not quite though
148
149
// adding a comment at the end of the line makes
149
150
// the ast::MacroCall to include the semicolon at the end
150
- let code = "
151
- let res = <|>dbg!(1 * 20); // needless comment
152
- " ;
153
- let expected = "
154
- let res = 1 * 20; // needless comment
155
- " ;
156
- check_assist ( remove_dbg, code, expected) ;
151
+ check_assist (
152
+ remove_dbg,
153
+ r#"let res = <|>dbg!(1 * 20); // needless comment"# ,
154
+ r#"let res = 1 * 20; // needless comment"# ,
155
+ ) ;
157
156
}
158
157
159
158
#[ test]
160
159
fn test_remove_dbg_keep_expression ( ) {
161
- let code = "
162
- let res = <|>dbg!(a + b).foo();" ;
163
- let expected = "let res = (a + b).foo();" ;
164
- check_assist ( remove_dbg, code, expected) ;
160
+ check_assist (
161
+ remove_dbg,
162
+ r#"let res = <|>dbg!(a + b).foo();"# ,
163
+ r#"let res = (a + b).foo();"# ,
164
+ ) ;
165
165
}
166
166
167
167
#[ test]
168
168
fn test_remove_dbg_from_inside_fn ( ) {
169
- let code = "
169
+ check_assist_target (
170
+ remove_dbg,
171
+ r#"
170
172
fn square(x: u32) -> u32 {
171
173
x * x
172
174
}
173
175
174
176
fn main() {
175
177
let x = square(dbg<|>!(5 + 10));
176
- println!(\" {}\" , x);
177
- }" ;
178
+ println!("{}", x);
179
+ }"# ,
180
+ "dbg!(5 + 10)" ,
181
+ ) ;
178
182
179
- let expected = "
183
+ check_assist (
184
+ remove_dbg,
185
+ r#"
186
+ fn square(x: u32) -> u32 {
187
+ x * x
188
+ }
189
+
190
+ fn main() {
191
+ let x = square(dbg<|>!(5 + 10));
192
+ println!("{}", x);
193
+ }"# ,
194
+ r#"
180
195
fn square(x: u32) -> u32 {
181
196
x * x
182
197
}
183
198
184
199
fn main() {
185
200
let x = square(5 + 10);
186
- println!(\" {}\" , x);
187
- }" ;
188
- check_assist_target ( remove_dbg, code, "dbg!(5 + 10)" ) ;
189
- check_assist ( remove_dbg, code, expected) ;
201
+ println!("{}", x);
202
+ }"# ,
203
+ ) ;
190
204
}
191
205
}
0 commit comments