aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/remove_dbg.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-02-09 08:52:09 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-02-09 08:52:09 +0000
commit3e8351fb0607f8711749b00d80f68bf25de01a76 (patch)
tree97388dafe71ececcbaf97249021b9c8d49786ccf /crates/ra_assists/src/remove_dbg.rs
parent12e3b4c70b5ef23b2fdfc197296d483680e125f9 (diff)
parent4fdeb54bb5c7ba0704839a65996766d223c51fc1 (diff)
Merge #768
768: Sort assists by the range of the affected element r=matklad a=robojumper Closes #763. https://github.com/rust-analyzer/rust-analyzer/blob/3be98f2ac93b278828e76eb813bdd8033f647b12/crates/ra_assists/src/lib.rs#L233-L236 This could be made more robust by a) adding a way to identify actions by things other than their label and b) allowing arbitrary actions to appear in the list as long as the tested actions are there in the correct order. Let me know if I should do any of that. Co-authored-by: robojumper <[email protected]>
Diffstat (limited to 'crates/ra_assists/src/remove_dbg.rs')
-rw-r--r--crates/ra_assists/src/remove_dbg.rs18
1 files changed, 17 insertions, 1 deletions
diff --git a/crates/ra_assists/src/remove_dbg.rs b/crates/ra_assists/src/remove_dbg.rs
index 40f97a849..e9d0a635b 100644
--- a/crates/ra_assists/src/remove_dbg.rs
+++ b/crates/ra_assists/src/remove_dbg.rs
@@ -47,6 +47,7 @@ pub(crate) fn remove_dbg(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
47 }; 47 };
48 48
49 ctx.build("remove dbg!()", |edit| { 49 ctx.build("remove dbg!()", |edit| {
50 edit.target(macro_call.syntax().range());
50 edit.replace(macro_range, macro_content); 51 edit.replace(macro_range, macro_content);
51 edit.set_cursor(cursor_pos); 52 edit.set_cursor(cursor_pos);
52 }) 53 })
@@ -78,7 +79,7 @@ fn is_valid_macrocall(macro_call: &ast::MacroCall, macro_name: &str) -> Option<b
78#[cfg(test)] 79#[cfg(test)]
79mod tests { 80mod tests {
80 use super::*; 81 use super::*;
81 use crate::helpers::{check_assist, check_assist_not_applicable}; 82 use crate::helpers::{check_assist, check_assist_not_applicable, check_assist_target};
82 83
83 #[test] 84 #[test]
84 fn test_remove_dbg() { 85 fn test_remove_dbg() {
@@ -120,4 +121,19 @@ fn foo(n: usize) {
120 check_assist_not_applicable(remove_dbg, "<|>dbg(5, 6, 7)"); 121 check_assist_not_applicable(remove_dbg, "<|>dbg(5, 6, 7)");
121 check_assist_not_applicable(remove_dbg, "<|>dbg!(5, 6, 7"); 122 check_assist_not_applicable(remove_dbg, "<|>dbg!(5, 6, 7");
122 } 123 }
124
125 #[test]
126 fn remove_dbg_target() {
127 check_assist_target(
128 remove_dbg,
129 "
130fn foo(n: usize) {
131 if let Some(_) = dbg!(n.<|>checked_sub(4)) {
132 // ...
133 }
134}
135",
136 "dbg!(n.checked_sub(4))",
137 );
138 }
123} 139}