diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-06-28 23:37:25 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-06-28 23:37:25 +0100 |
commit | ca31b1d63ae91a69f1ce9c0b075403834ba19f38 (patch) | |
tree | df719c1ccd7cbd174b79ca50ffd0052731d1ea86 /crates/ra_assists/src/handlers/change_visibility.rs | |
parent | 11f31ae4c3a38831609e4591e751ce10c4e38daf (diff) | |
parent | 36128c170d9d938cfcc52bc851aaed1fab6a2ad9 (diff) |
Merge #5105
5105: Simlify with matches!() r=matklad a=Veetaha
Co-authored-by: Veetaha <[email protected]>
Diffstat (limited to 'crates/ra_assists/src/handlers/change_visibility.rs')
-rw-r--r-- | crates/ra_assists/src/handlers/change_visibility.rs | 25 |
1 files changed, 5 insertions, 20 deletions
diff --git a/crates/ra_assists/src/handlers/change_visibility.rs b/crates/ra_assists/src/handlers/change_visibility.rs index c21d75be0..157c7b665 100644 --- a/crates/ra_assists/src/handlers/change_visibility.rs +++ b/crates/ra_assists/src/handlers/change_visibility.rs | |||
@@ -1,15 +1,12 @@ | |||
1 | use ra_syntax::{ | 1 | use ra_syntax::{ |
2 | ast::{self, NameOwner, VisibilityOwner}, | 2 | ast::{self, NameOwner, VisibilityOwner}, |
3 | AstNode, | 3 | AstNode, |
4 | SyntaxKind::{ | 4 | SyntaxKind::{CONST_DEF, ENUM_DEF, FN_DEF, MODULE, STRUCT_DEF, TRAIT_DEF, VISIBILITY}, |
5 | ATTR, COMMENT, CONST_DEF, ENUM_DEF, FN_DEF, MODULE, STRUCT_DEF, TRAIT_DEF, VISIBILITY, | 5 | T, |
6 | WHITESPACE, | ||
7 | }, | ||
8 | SyntaxNode, TextSize, T, | ||
9 | }; | 6 | }; |
10 | use test_utils::mark; | 7 | use test_utils::mark; |
11 | 8 | ||
12 | use crate::{AssistContext, AssistId, Assists}; | 9 | use crate::{utils::vis_offset, AssistContext, AssistId, Assists}; |
13 | 10 | ||
14 | // Assist: change_visibility | 11 | // Assist: change_visibility |
15 | // | 12 | // |
@@ -30,9 +27,8 @@ pub(crate) fn change_visibility(acc: &mut Assists, ctx: &AssistContext) -> Optio | |||
30 | } | 27 | } |
31 | 28 | ||
32 | fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { | 29 | fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { |
33 | let item_keyword = ctx.token_at_offset().find(|leaf| match leaf.kind() { | 30 | let item_keyword = ctx.token_at_offset().find(|leaf| { |
34 | T![const] | T![fn] | T![mod] | T![struct] | T![enum] | T![trait] => true, | 31 | matches!(leaf.kind(), T![const] | T![fn] | T![mod] | T![struct] | T![enum] | T![trait]) |
35 | _ => false, | ||
36 | }); | 32 | }); |
37 | 33 | ||
38 | let (offset, target) = if let Some(keyword) = item_keyword { | 34 | let (offset, target) = if let Some(keyword) = item_keyword { |
@@ -71,17 +67,6 @@ fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { | |||
71 | }) | 67 | }) |
72 | } | 68 | } |
73 | 69 | ||
74 | fn vis_offset(node: &SyntaxNode) -> TextSize { | ||
75 | node.children_with_tokens() | ||
76 | .skip_while(|it| match it.kind() { | ||
77 | WHITESPACE | COMMENT | ATTR => true, | ||
78 | _ => false, | ||
79 | }) | ||
80 | .next() | ||
81 | .map(|it| it.text_range().start()) | ||
82 | .unwrap_or_else(|| node.text_range().start()) | ||
83 | } | ||
84 | |||
85 | fn change_vis(acc: &mut Assists, vis: ast::Visibility) -> Option<()> { | 70 | fn change_vis(acc: &mut Assists, vis: ast::Visibility) -> Option<()> { |
86 | if vis.syntax().text() == "pub" { | 71 | if vis.syntax().text() == "pub" { |
87 | let target = vis.syntax().text_range(); | 72 | let target = vis.syntax().text_range(); |