diff options
Diffstat (limited to 'crates/ra_assists/src/change_visibility.rs')
-rw-r--r-- | crates/ra_assists/src/change_visibility.rs | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/crates/ra_assists/src/change_visibility.rs b/crates/ra_assists/src/change_visibility.rs index ab10d2aa4..d28cdd07b 100644 --- a/crates/ra_assists/src/change_visibility.rs +++ b/crates/ra_assists/src/change_visibility.rs | |||
@@ -35,14 +35,15 @@ fn add_vis(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | |||
35 | if parent.children().any(|child| child.kind() == VISIBILITY) { | 35 | if parent.children().any(|child| child.kind() == VISIBILITY) { |
36 | return None; | 36 | return None; |
37 | } | 37 | } |
38 | (vis_offset(&parent), keyword.range()) | 38 | (vis_offset(&parent), keyword.text_range()) |
39 | } else { | 39 | } else { |
40 | let ident = ctx.token_at_offset().find(|leaf| leaf.kind() == IDENT)?; | 40 | let ident = ctx.token_at_offset().find(|leaf| leaf.kind() == IDENT)?; |
41 | let field = ident.parent().ancestors().find_map(ast::NamedFieldDef::cast)?; | 41 | let field = ident.parent().ancestors().find_map(ast::NamedFieldDef::cast)?; |
42 | if field.name()?.syntax().range() != ident.range() && field.visibility().is_some() { | 42 | if field.name()?.syntax().text_range() != ident.text_range() && field.visibility().is_some() |
43 | { | ||
43 | return None; | 44 | return None; |
44 | } | 45 | } |
45 | (vis_offset(field.syntax()), ident.range()) | 46 | (vis_offset(field.syntax()), ident.text_range()) |
46 | }; | 47 | }; |
47 | 48 | ||
48 | ctx.add_action(AssistId("change_visibility"), "make pub(crate)", |edit| { | 49 | ctx.add_action(AssistId("change_visibility"), "make pub(crate)", |edit| { |
@@ -61,25 +62,25 @@ fn vis_offset(node: &SyntaxNode) -> TextUnit { | |||
61 | _ => false, | 62 | _ => false, |
62 | }) | 63 | }) |
63 | .next() | 64 | .next() |
64 | .map(|it| it.range().start()) | 65 | .map(|it| it.text_range().start()) |
65 | .unwrap_or_else(|| node.range().start()) | 66 | .unwrap_or_else(|| node.text_range().start()) |
66 | } | 67 | } |
67 | 68 | ||
68 | fn change_vis(mut ctx: AssistCtx<impl HirDatabase>, vis: ast::Visibility) -> Option<Assist> { | 69 | fn change_vis(mut ctx: AssistCtx<impl HirDatabase>, vis: ast::Visibility) -> Option<Assist> { |
69 | if vis.syntax().text() == "pub" { | 70 | if vis.syntax().text() == "pub" { |
70 | ctx.add_action(AssistId("change_visibility"), "change to pub(crate)", |edit| { | 71 | ctx.add_action(AssistId("change_visibility"), "change to pub(crate)", |edit| { |
71 | edit.target(vis.syntax().range()); | 72 | edit.target(vis.syntax().text_range()); |
72 | edit.replace(vis.syntax().range(), "pub(crate)"); | 73 | edit.replace(vis.syntax().text_range(), "pub(crate)"); |
73 | edit.set_cursor(vis.syntax().range().start()) | 74 | edit.set_cursor(vis.syntax().text_range().start()) |
74 | }); | 75 | }); |
75 | 76 | ||
76 | return ctx.build(); | 77 | return ctx.build(); |
77 | } | 78 | } |
78 | if vis.syntax().text() == "pub(crate)" { | 79 | if vis.syntax().text() == "pub(crate)" { |
79 | ctx.add_action(AssistId("change_visibility"), "change to pub", |edit| { | 80 | ctx.add_action(AssistId("change_visibility"), "change to pub", |edit| { |
80 | edit.target(vis.syntax().range()); | 81 | edit.target(vis.syntax().text_range()); |
81 | edit.replace(vis.syntax().range(), "pub"); | 82 | edit.replace(vis.syntax().text_range(), "pub"); |
82 | edit.set_cursor(vis.syntax().range().start()); | 83 | edit.set_cursor(vis.syntax().text_range().start()); |
83 | }); | 84 | }); |
84 | 85 | ||
85 | return ctx.build(); | 86 | return ctx.build(); |