diff options
author | Andrea Pretto <[email protected]> | 2019-02-11 17:07:21 +0000 |
---|---|---|
committer | Andrea Pretto <[email protected]> | 2019-02-11 17:07:21 +0000 |
commit | 5c9c0d3ae2735b4b32a44742bac800ca616fdde8 (patch) | |
tree | 8ad5dc9a548915729bcc87085a1a145d4ba2a00a /crates/ra_assists/src/change_visibility.rs | |
parent | af62fde57fe58f4aa06608568dc26535731800a0 (diff) |
ra_assists: assist "providers" can produce multiple assists
Diffstat (limited to 'crates/ra_assists/src/change_visibility.rs')
-rw-r--r-- | crates/ra_assists/src/change_visibility.rs | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/crates/ra_assists/src/change_visibility.rs b/crates/ra_assists/src/change_visibility.rs index 6d9a4eec2..c2ba897a4 100644 --- a/crates/ra_assists/src/change_visibility.rs +++ b/crates/ra_assists/src/change_visibility.rs | |||
@@ -14,7 +14,7 @@ pub(crate) fn change_visibility(ctx: AssistCtx<impl HirDatabase>) -> Option<Assi | |||
14 | add_vis(ctx) | 14 | add_vis(ctx) |
15 | } | 15 | } |
16 | 16 | ||
17 | fn add_vis(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | 17 | fn add_vis(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { |
18 | let item_keyword = ctx.leaf_at_offset().find(|leaf| match leaf.kind() { | 18 | let item_keyword = ctx.leaf_at_offset().find(|leaf| match leaf.kind() { |
19 | FN_KW | MOD_KW | STRUCT_KW | ENUM_KW | TRAIT_KW => true, | 19 | FN_KW | MOD_KW | STRUCT_KW | ENUM_KW | TRAIT_KW => true, |
20 | _ => false, | 20 | _ => false, |
@@ -41,11 +41,13 @@ fn add_vis(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | |||
41 | (vis_offset(field.syntax()), ident.range()) | 41 | (vis_offset(field.syntax()), ident.range()) |
42 | }; | 42 | }; |
43 | 43 | ||
44 | ctx.build("make pub(crate)", |edit| { | 44 | ctx.add_action("make pub(crate)", |edit| { |
45 | edit.target(target); | 45 | edit.target(target); |
46 | edit.insert(offset, "pub(crate) "); | 46 | edit.insert(offset, "pub(crate) "); |
47 | edit.set_cursor(offset); | 47 | edit.set_cursor(offset); |
48 | }) | 48 | }); |
49 | |||
50 | ctx.build() | ||
49 | } | 51 | } |
50 | 52 | ||
51 | fn vis_offset(node: &SyntaxNode) -> TextUnit { | 53 | fn vis_offset(node: &SyntaxNode) -> TextUnit { |
@@ -59,20 +61,24 @@ fn vis_offset(node: &SyntaxNode) -> TextUnit { | |||
59 | .unwrap_or(node.range().start()) | 61 | .unwrap_or(node.range().start()) |
60 | } | 62 | } |
61 | 63 | ||
62 | fn change_vis(ctx: AssistCtx<impl HirDatabase>, vis: &ast::Visibility) -> Option<Assist> { | 64 | fn change_vis(mut ctx: AssistCtx<impl HirDatabase>, vis: &ast::Visibility) -> Option<Assist> { |
63 | if vis.syntax().text() == "pub" { | 65 | if vis.syntax().text() == "pub" { |
64 | return ctx.build("change to pub(crate)", |edit| { | 66 | ctx.add_action("change to pub(crate)", |edit| { |
65 | edit.target(vis.syntax().range()); | 67 | edit.target(vis.syntax().range()); |
66 | edit.replace(vis.syntax().range(), "pub(crate)"); | 68 | edit.replace(vis.syntax().range(), "pub(crate)"); |
67 | edit.set_cursor(vis.syntax().range().start()); | 69 | edit.set_cursor(vis.syntax().range().start()) |
68 | }); | 70 | }); |
71 | |||
72 | return ctx.build(); | ||
69 | } | 73 | } |
70 | if vis.syntax().text() == "pub(crate)" { | 74 | if vis.syntax().text() == "pub(crate)" { |
71 | return ctx.build("change to pub", |edit| { | 75 | ctx.add_action("change to pub", |edit| { |
72 | edit.target(vis.syntax().range()); | 76 | edit.target(vis.syntax().range()); |
73 | edit.replace(vis.syntax().range(), "pub"); | 77 | edit.replace(vis.syntax().range(), "pub"); |
74 | edit.set_cursor(vis.syntax().range().start()); | 78 | edit.set_cursor(vis.syntax().range().start()); |
75 | }); | 79 | }); |
80 | |||
81 | return ctx.build(); | ||
76 | } | 82 | } |
77 | None | 83 | None |
78 | } | 84 | } |