diff options
author | robojumper <[email protected]> | 2019-02-08 21:43:13 +0000 |
---|---|---|
committer | robojumper <[email protected]> | 2019-02-08 21:43:13 +0000 |
commit | a3622eb629bf7acea933d956f8cee902ae357fca (patch) | |
tree | e09c517a22f7cf4229c8d4a306f68d9f3940adec /crates/ra_assists/src/change_visibility.rs | |
parent | 12e3b4c70b5ef23b2fdfc197296d483680e125f9 (diff) |
Add some assist ranges
Diffstat (limited to 'crates/ra_assists/src/change_visibility.rs')
-rw-r--r-- | crates/ra_assists/src/change_visibility.rs | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/crates/ra_assists/src/change_visibility.rs b/crates/ra_assists/src/change_visibility.rs index fa5f231c8..73dd8319f 100644 --- a/crates/ra_assists/src/change_visibility.rs +++ b/crates/ra_assists/src/change_visibility.rs | |||
@@ -20,7 +20,7 @@ fn add_vis(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | |||
20 | _ => false, | 20 | _ => false, |
21 | }); | 21 | }); |
22 | 22 | ||
23 | let offset = if let Some(keyword) = item_keyword { | 23 | let (offset, target) = if let Some(keyword) = item_keyword { |
24 | let parent = keyword.parent()?; | 24 | let parent = keyword.parent()?; |
25 | let def_kws = vec![FN_DEF, MODULE, STRUCT_DEF, ENUM_DEF, TRAIT_DEF]; | 25 | let def_kws = vec![FN_DEF, MODULE, STRUCT_DEF, ENUM_DEF, TRAIT_DEF]; |
26 | // Parent is not a definition, can't add visibility | 26 | // Parent is not a definition, can't add visibility |
@@ -31,17 +31,18 @@ fn add_vis(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | |||
31 | if parent.children().any(|child| child.kind() == VISIBILITY) { | 31 | if parent.children().any(|child| child.kind() == VISIBILITY) { |
32 | return None; | 32 | return None; |
33 | } | 33 | } |
34 | vis_offset(parent) | 34 | (vis_offset(parent), parent.range()) |
35 | } else { | 35 | } else { |
36 | let ident = ctx.leaf_at_offset().find(|leaf| leaf.kind() == IDENT)?; | 36 | let ident = ctx.leaf_at_offset().find(|leaf| leaf.kind() == IDENT)?; |
37 | let field = ident.ancestors().find_map(ast::NamedFieldDef::cast)?; | 37 | let field = ident.ancestors().find_map(ast::NamedFieldDef::cast)?; |
38 | if field.name()?.syntax().range() != ident.range() && field.visibility().is_some() { | 38 | if field.name()?.syntax().range() != ident.range() && field.visibility().is_some() { |
39 | return None; | 39 | return None; |
40 | } | 40 | } |
41 | vis_offset(field.syntax()) | 41 | (vis_offset(field.syntax()), field.syntax().range()) |
42 | }; | 42 | }; |
43 | 43 | ||
44 | ctx.build("make pub(crate)", |edit| { | 44 | ctx.build("make pub(crate)", |edit| { |
45 | edit.target(target); | ||
45 | edit.insert(offset, "pub(crate) "); | 46 | edit.insert(offset, "pub(crate) "); |
46 | edit.set_cursor(offset); | 47 | edit.set_cursor(offset); |
47 | }) | 48 | }) |
@@ -60,13 +61,15 @@ fn vis_offset(node: &SyntaxNode) -> TextUnit { | |||
60 | 61 | ||
61 | fn change_vis(ctx: AssistCtx<impl HirDatabase>, vis: &ast::Visibility) -> Option<Assist> { | 62 | fn change_vis(ctx: AssistCtx<impl HirDatabase>, vis: &ast::Visibility) -> Option<Assist> { |
62 | if vis.syntax().text() == "pub" { | 63 | if vis.syntax().text() == "pub" { |
63 | return ctx.build("chage to pub(crate)", |edit| { | 64 | return ctx.build("change to pub(crate)", |edit| { |
65 | edit.target(vis.syntax().range()); | ||
64 | edit.replace(vis.syntax().range(), "pub(crate)"); | 66 | edit.replace(vis.syntax().range(), "pub(crate)"); |
65 | edit.set_cursor(vis.syntax().range().start()); | 67 | edit.set_cursor(vis.syntax().range().start()); |
66 | }); | 68 | }); |
67 | } | 69 | } |
68 | if vis.syntax().text() == "pub(crate)" { | 70 | if vis.syntax().text() == "pub(crate)" { |
69 | return ctx.build("chage to pub", |edit| { | 71 | return ctx.build("change to pub", |edit| { |
72 | edit.target(vis.syntax().range()); | ||
70 | edit.replace(vis.syntax().range(), "pub"); | 73 | edit.replace(vis.syntax().range(), "pub"); |
71 | edit.set_cursor(vis.syntax().range().start()); | 74 | edit.set_cursor(vis.syntax().range().start()); |
72 | }); | 75 | }); |