aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/handlers
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-06-28 23:37:25 +0100
committerGitHub <[email protected]>2020-06-28 23:37:25 +0100
commitca31b1d63ae91a69f1ce9c0b075403834ba19f38 (patch)
treedf719c1ccd7cbd174b79ca50ffd0052731d1ea86 /crates/ra_assists/src/handlers
parent11f31ae4c3a38831609e4591e751ce10c4e38daf (diff)
parent36128c170d9d938cfcc52bc851aaed1fab6a2ad9 (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')
-rw-r--r--crates/ra_assists/src/handlers/change_visibility.rs25
-rw-r--r--crates/ra_assists/src/handlers/fix_visibility.rs19
-rw-r--r--crates/ra_assists/src/handlers/merge_match_arms.rs5
3 files changed, 8 insertions, 41 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 @@
1use ra_syntax::{ 1use 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};
10use test_utils::mark; 7use test_utils::mark;
11 8
12use crate::{AssistContext, AssistId, Assists}; 9use 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
32fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { 29fn 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
74fn 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
85fn change_vis(acc: &mut Assists, vis: ast::Visibility) -> Option<()> { 70fn 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();
diff --git a/crates/ra_assists/src/handlers/fix_visibility.rs b/crates/ra_assists/src/handlers/fix_visibility.rs
index 54601d1f3..19d4dac5e 100644
--- a/crates/ra_assists/src/handlers/fix_visibility.rs
+++ b/crates/ra_assists/src/handlers/fix_visibility.rs
@@ -1,12 +1,8 @@
1use hir::{db::HirDatabase, HasSource, HasVisibility, PathResolution}; 1use hir::{db::HirDatabase, HasSource, HasVisibility, PathResolution};
2use ra_db::FileId; 2use ra_db::FileId;
3use ra_syntax::{ 3use ra_syntax::{ast, AstNode, TextRange, TextSize};
4 ast, AstNode,
5 SyntaxKind::{ATTR, COMMENT, WHITESPACE},
6 SyntaxNode, TextRange, TextSize,
7};
8 4
9use crate::{AssistContext, AssistId, Assists}; 5use crate::{utils::vis_offset, AssistContext, AssistId, Assists};
10 6
11// FIXME: this really should be a fix for diagnostic, rather than an assist. 7// FIXME: this really should be a fix for diagnostic, rather than an assist.
12 8
@@ -177,17 +173,6 @@ fn target_data_for_def(
177 Some((offset, target, target_file, target_name)) 173 Some((offset, target, target_file, target_name))
178} 174}
179 175
180fn vis_offset(node: &SyntaxNode) -> TextSize {
181 node.children_with_tokens()
182 .skip_while(|it| match it.kind() {
183 WHITESPACE | COMMENT | ATTR => true,
184 _ => false,
185 })
186 .next()
187 .map(|it| it.text_range().start())
188 .unwrap_or_else(|| node.text_range().start())
189}
190
191#[cfg(test)] 176#[cfg(test)]
192mod tests { 177mod tests {
193 use crate::tests::{check_assist, check_assist_not_applicable}; 178 use crate::tests::{check_assist, check_assist_not_applicable};
diff --git a/crates/ra_assists/src/handlers/merge_match_arms.rs b/crates/ra_assists/src/handlers/merge_match_arms.rs
index ca04ec671..90ce66378 100644
--- a/crates/ra_assists/src/handlers/merge_match_arms.rs
+++ b/crates/ra_assists/src/handlers/merge_match_arms.rs
@@ -81,10 +81,7 @@ pub(crate) fn merge_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option
81} 81}
82 82
83fn contains_placeholder(a: &ast::MatchArm) -> bool { 83fn contains_placeholder(a: &ast::MatchArm) -> bool {
84 match a.pat() { 84 matches!(a.pat(), Some(ast::Pat::PlaceholderPat(..)))
85 Some(ra_syntax::ast::Pat::PlaceholderPat(..)) => true,
86 _ => false,
87 }
88} 85}
89 86
90#[cfg(test)] 87#[cfg(test)]