diff options
Diffstat (limited to 'crates/ra_assists/src/assists/remove_dbg.rs')
-rw-r--r-- | crates/ra_assists/src/assists/remove_dbg.rs | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/crates/ra_assists/src/assists/remove_dbg.rs b/crates/ra_assists/src/assists/remove_dbg.rs index 1a7e2b305..aedf8747f 100644 --- a/crates/ra_assists/src/assists/remove_dbg.rs +++ b/crates/ra_assists/src/assists/remove_dbg.rs | |||
@@ -1,14 +1,28 @@ | |||
1 | //! FIXME: write short doc here | ||
2 | |||
3 | use crate::{Assist, AssistCtx, AssistId}; | ||
4 | use hir::db::HirDatabase; | 1 | use hir::db::HirDatabase; |
5 | use ra_syntax::{ | 2 | use ra_syntax::{ |
6 | ast::{self, AstNode}, | 3 | ast::{self, AstNode}, |
7 | TextUnit, T, | 4 | TextUnit, T, |
8 | }; | 5 | }; |
9 | 6 | ||
10 | pub(crate) fn remove_dbg(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | 7 | use crate::{Assist, AssistCtx, AssistId}; |
11 | let macro_call = ctx.node_at_offset::<ast::MacroCall>()?; | 8 | |
9 | // Assist: remove_dbg | ||
10 | // | ||
11 | // Removes `dbg!()` macro call. | ||
12 | // | ||
13 | // ``` | ||
14 | // fn main() { | ||
15 | // <|>dbg!(92); | ||
16 | // } | ||
17 | // ``` | ||
18 | // -> | ||
19 | // ``` | ||
20 | // fn main() { | ||
21 | // 92; | ||
22 | // } | ||
23 | // ``` | ||
24 | pub(crate) fn remove_dbg(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | ||
25 | let macro_call = ctx.find_node_at_offset::<ast::MacroCall>()?; | ||
12 | 26 | ||
13 | if !is_valid_macrocall(¯o_call, "dbg")? { | 27 | if !is_valid_macrocall(¯o_call, "dbg")? { |
14 | return None; | 28 | return None; |
@@ -44,13 +58,11 @@ pub(crate) fn remove_dbg(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> | |||
44 | text.slice(without_parens).to_string() | 58 | text.slice(without_parens).to_string() |
45 | }; | 59 | }; |
46 | 60 | ||
47 | ctx.add_action(AssistId("remove_dbg"), "remove dbg!()", |edit| { | 61 | ctx.add_assist(AssistId("remove_dbg"), "remove dbg!()", |edit| { |
48 | edit.target(macro_call.syntax().text_range()); | 62 | edit.target(macro_call.syntax().text_range()); |
49 | edit.replace(macro_range, macro_content); | 63 | edit.replace(macro_range, macro_content); |
50 | edit.set_cursor(cursor_pos); | 64 | edit.set_cursor(cursor_pos); |
51 | }); | 65 | }) |
52 | |||
53 | ctx.build() | ||
54 | } | 66 | } |
55 | 67 | ||
56 | /// Verifies that the given macro_call actually matches the given name | 68 | /// Verifies that the given macro_call actually matches the given name |