aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/handlers/change_visibility.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists/src/handlers/change_visibility.rs')
-rw-r--r--crates/ra_assists/src/handlers/change_visibility.rs34
1 files changed, 22 insertions, 12 deletions
diff --git a/crates/ra_assists/src/handlers/change_visibility.rs b/crates/ra_assists/src/handlers/change_visibility.rs
index 1cd532e80..489db83e6 100644
--- a/crates/ra_assists/src/handlers/change_visibility.rs
+++ b/crates/ra_assists/src/handlers/change_visibility.rs
@@ -66,11 +66,15 @@ fn add_vis(ctx: AssistCtx) -> Option<Assist> {
66 return None; 66 return None;
67 }; 67 };
68 68
69 ctx.add_assist(AssistId("change_visibility"), "Change visibility to pub(crate)", |edit| { 69 ctx.add_assist(
70 edit.target(target); 70 AssistId("change_visibility"),
71 edit.insert(offset, "pub(crate) "); 71 "Change visibility to pub(crate)",
72 edit.set_cursor(offset); 72 target,
73 }) 73 |edit| {
74 edit.insert(offset, "pub(crate) ");
75 edit.set_cursor(offset);
76 },
77 )
74} 78}
75 79
76fn vis_offset(node: &SyntaxNode) -> TextSize { 80fn vis_offset(node: &SyntaxNode) -> TextSize {
@@ -86,22 +90,28 @@ fn vis_offset(node: &SyntaxNode) -> TextSize {
86 90
87fn change_vis(ctx: AssistCtx, vis: ast::Visibility) -> Option<Assist> { 91fn change_vis(ctx: AssistCtx, vis: ast::Visibility) -> Option<Assist> {
88 if vis.syntax().text() == "pub" { 92 if vis.syntax().text() == "pub" {
93 let target = vis.syntax().text_range();
89 return ctx.add_assist( 94 return ctx.add_assist(
90 AssistId("change_visibility"), 95 AssistId("change_visibility"),
91 "Change Visibility to pub(crate)", 96 "Change Visibility to pub(crate)",
97 target,
92 |edit| { 98 |edit| {
93 edit.target(vis.syntax().text_range());
94 edit.replace(vis.syntax().text_range(), "pub(crate)"); 99 edit.replace(vis.syntax().text_range(), "pub(crate)");
95 edit.set_cursor(vis.syntax().text_range().start()) 100 edit.set_cursor(vis.syntax().text_range().start())
96 }, 101 },
97 ); 102 );
98 } 103 }
99 if vis.syntax().text() == "pub(crate)" { 104 if vis.syntax().text() == "pub(crate)" {
100 return ctx.add_assist(AssistId("change_visibility"), "Change visibility to pub", |edit| { 105 let target = vis.syntax().text_range();
101 edit.target(vis.syntax().text_range()); 106 return ctx.add_assist(
102 edit.replace(vis.syntax().text_range(), "pub"); 107 AssistId("change_visibility"),
103 edit.set_cursor(vis.syntax().text_range().start()); 108 "Change visibility to pub",
104 }); 109 target,
110 |edit| {
111 edit.replace(vis.syntax().text_range(), "pub");
112 edit.set_cursor(vis.syntax().text_range().start());
113 },
114 );
105 } 115 }
106 None 116 None
107} 117}
@@ -110,7 +120,7 @@ fn change_vis(ctx: AssistCtx, vis: ast::Visibility) -> Option<Assist> {
110mod tests { 120mod tests {
111 use test_utils::covers; 121 use test_utils::covers;
112 122
113 use crate::helpers::{check_assist, check_assist_not_applicable, check_assist_target}; 123 use crate::tests::{check_assist, check_assist_not_applicable, check_assist_target};
114 124
115 use super::*; 125 use super::*;
116 126