diff options
Diffstat (limited to 'crates/ra_assists/src/handlers/change_visibility.rs')
-rw-r--r-- | crates/ra_assists/src/handlers/change_visibility.rs | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/crates/ra_assists/src/handlers/change_visibility.rs b/crates/ra_assists/src/handlers/change_visibility.rs index 489db83e6..e631766ef 100644 --- a/crates/ra_assists/src/handlers/change_visibility.rs +++ b/crates/ra_assists/src/handlers/change_visibility.rs | |||
@@ -7,10 +7,10 @@ use ra_syntax::{ | |||
7 | }, | 7 | }, |
8 | SyntaxNode, TextSize, T, | 8 | SyntaxNode, TextSize, T, |
9 | }; | 9 | }; |
10 | |||
11 | use crate::{Assist, AssistCtx, AssistId}; | ||
12 | use test_utils::tested_by; | 10 | use test_utils::tested_by; |
13 | 11 | ||
12 | use crate::{AssistContext, AssistId, Assists}; | ||
13 | |||
14 | // Assist: change_visibility | 14 | // Assist: change_visibility |
15 | // | 15 | // |
16 | // Adds or changes existing visibility specifier. | 16 | // Adds or changes existing visibility specifier. |
@@ -22,14 +22,14 @@ use test_utils::tested_by; | |||
22 | // ``` | 22 | // ``` |
23 | // pub(crate) fn frobnicate() {} | 23 | // pub(crate) fn frobnicate() {} |
24 | // ``` | 24 | // ``` |
25 | pub(crate) fn change_visibility(ctx: AssistCtx) -> Option<Assist> { | 25 | pub(crate) fn change_visibility(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { |
26 | if let Some(vis) = ctx.find_node_at_offset::<ast::Visibility>() { | 26 | if let Some(vis) = ctx.find_node_at_offset::<ast::Visibility>() { |
27 | return change_vis(ctx, vis); | 27 | return change_vis(acc, vis); |
28 | } | 28 | } |
29 | add_vis(ctx) | 29 | add_vis(acc, ctx) |
30 | } | 30 | } |
31 | 31 | ||
32 | fn add_vis(ctx: AssistCtx) -> Option<Assist> { | 32 | fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { |
33 | let item_keyword = ctx.token_at_offset().find(|leaf| match leaf.kind() { | 33 | let item_keyword = ctx.token_at_offset().find(|leaf| match leaf.kind() { |
34 | T![const] | T![fn] | T![mod] | T![struct] | T![enum] | T![trait] => true, | 34 | T![const] | T![fn] | T![mod] | T![struct] | T![enum] | T![trait] => true, |
35 | _ => false, | 35 | _ => false, |
@@ -66,15 +66,10 @@ fn add_vis(ctx: AssistCtx) -> Option<Assist> { | |||
66 | return None; | 66 | return None; |
67 | }; | 67 | }; |
68 | 68 | ||
69 | ctx.add_assist( | 69 | acc.add(AssistId("change_visibility"), "Change visibility to pub(crate)", target, |edit| { |
70 | AssistId("change_visibility"), | 70 | edit.insert(offset, "pub(crate) "); |
71 | "Change visibility to pub(crate)", | 71 | edit.set_cursor(offset); |
72 | target, | 72 | }) |
73 | |edit| { | ||
74 | edit.insert(offset, "pub(crate) "); | ||
75 | edit.set_cursor(offset); | ||
76 | }, | ||
77 | ) | ||
78 | } | 73 | } |
79 | 74 | ||
80 | fn vis_offset(node: &SyntaxNode) -> TextSize { | 75 | fn vis_offset(node: &SyntaxNode) -> TextSize { |
@@ -88,10 +83,10 @@ fn vis_offset(node: &SyntaxNode) -> TextSize { | |||
88 | .unwrap_or_else(|| node.text_range().start()) | 83 | .unwrap_or_else(|| node.text_range().start()) |
89 | } | 84 | } |
90 | 85 | ||
91 | fn change_vis(ctx: AssistCtx, vis: ast::Visibility) -> Option<Assist> { | 86 | fn change_vis(acc: &mut Assists, vis: ast::Visibility) -> Option<()> { |
92 | if vis.syntax().text() == "pub" { | 87 | if vis.syntax().text() == "pub" { |
93 | let target = vis.syntax().text_range(); | 88 | let target = vis.syntax().text_range(); |
94 | return ctx.add_assist( | 89 | return acc.add( |
95 | AssistId("change_visibility"), | 90 | AssistId("change_visibility"), |
96 | "Change Visibility to pub(crate)", | 91 | "Change Visibility to pub(crate)", |
97 | target, | 92 | target, |
@@ -103,7 +98,7 @@ fn change_vis(ctx: AssistCtx, vis: ast::Visibility) -> Option<Assist> { | |||
103 | } | 98 | } |
104 | if vis.syntax().text() == "pub(crate)" { | 99 | if vis.syntax().text() == "pub(crate)" { |
105 | let target = vis.syntax().text_range(); | 100 | let target = vis.syntax().text_range(); |
106 | return ctx.add_assist( | 101 | return acc.add( |
107 | AssistId("change_visibility"), | 102 | AssistId("change_visibility"), |
108 | "Change visibility to pub", | 103 | "Change visibility to pub", |
109 | target, | 104 | target, |