aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src
diff options
context:
space:
mode:
authorVeetaha <[email protected]>2020-06-28 23:18:50 +0100
committerVeetaha <[email protected]>2020-06-28 23:18:50 +0100
commit503f9498cd469c6467250c02bd8f6dbce973dd57 (patch)
treea4809da64326fca4533fa08c2beeb01fb04d160c /crates/ra_assists/src
parente75e2ae5b6b6b1364368ceb3d4081b6508b2f001 (diff)
Follow matklad suggestions
- Move vis_offset() to utils.rs - Shorten explicit ra_syntax::ast -> ast - Undo refactoring exhaustive pattern to non-exhaustive
Diffstat (limited to 'crates/ra_assists/src')
-rw-r--r--crates/ra_assists/src/handlers/change_visibility.rs9
-rw-r--r--crates/ra_assists/src/handlers/fix_visibility.rs9
-rw-r--r--crates/ra_assists/src/handlers/merge_match_arms.rs2
-rw-r--r--crates/ra_assists/src/utils.rs11
4 files changed, 13 insertions, 18 deletions
diff --git a/crates/ra_assists/src/handlers/change_visibility.rs b/crates/ra_assists/src/handlers/change_visibility.rs
index 18e92e393..237adbc7b 100644
--- a/crates/ra_assists/src/handlers/change_visibility.rs
+++ b/crates/ra_assists/src/handlers/change_visibility.rs
@@ -9,7 +9,7 @@ use ra_syntax::{
9}; 9};
10use test_utils::mark; 10use test_utils::mark;
11 11
12use crate::{AssistContext, AssistId, Assists}; 12use crate::{utils::vis_offset, AssistContext, AssistId, Assists};
13 13
14// Assist: change_visibility 14// Assist: change_visibility
15// 15//
@@ -70,13 +70,6 @@ fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
70 }) 70 })
71} 71}
72 72
73fn vis_offset(node: &SyntaxNode) -> TextSize {
74 node.children_with_tokens()
75 .find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR))
76 .map(|it| it.text_range().start())
77 .unwrap_or_else(|| node.text_range().start())
78}
79
80fn change_vis(acc: &mut Assists, vis: ast::Visibility) -> Option<()> { 73fn change_vis(acc: &mut Assists, vis: ast::Visibility) -> Option<()> {
81 if vis.syntax().text() == "pub" { 74 if vis.syntax().text() == "pub" {
82 let target = vis.syntax().text_range(); 75 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 02763c5b9..468f9a77f 100644
--- a/crates/ra_assists/src/handlers/fix_visibility.rs
+++ b/crates/ra_assists/src/handlers/fix_visibility.rs
@@ -6,7 +6,7 @@ use ra_syntax::{
6 SyntaxNode, TextRange, TextSize, 6 SyntaxNode, TextRange, TextSize,
7}; 7};
8 8
9use crate::{AssistContext, AssistId, Assists}; 9use crate::{utils::vis_offset, AssistContext, AssistId, Assists};
10 10
11// FIXME: this really should be a fix for diagnostic, rather than an assist. 11// FIXME: this really should be a fix for diagnostic, rather than an assist.
12 12
@@ -177,13 +177,6 @@ fn target_data_for_def(
177 Some((offset, target, target_file, target_name)) 177 Some((offset, target, target_file, target_name))
178} 178}
179 179
180fn vis_offset(node: &SyntaxNode) -> TextSize {
181 node.children_with_tokens()
182 .find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR))
183 .map(|it| it.text_range().start())
184 .unwrap_or_else(|| node.text_range().start())
185}
186
187#[cfg(test)] 180#[cfg(test)]
188mod tests { 181mod tests {
189 use crate::tests::{check_assist, check_assist_not_applicable}; 182 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 53c2c130f..90ce66378 100644
--- a/crates/ra_assists/src/handlers/merge_match_arms.rs
+++ b/crates/ra_assists/src/handlers/merge_match_arms.rs
@@ -81,7 +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 matches!(a.pat(), Some(ra_syntax::ast::Pat::PlaceholderPat(..))) 84 matches!(a.pat(), Some(ast::Pat::PlaceholderPat(..)))
85} 85}
86 86
87#[cfg(test)] 87#[cfg(test)]
diff --git a/crates/ra_assists/src/utils.rs b/crates/ra_assists/src/utils.rs
index b7c45a619..02de902d6 100644
--- a/crates/ra_assists/src/utils.rs
+++ b/crates/ra_assists/src/utils.rs
@@ -7,7 +7,9 @@ use hir::{Adt, Crate, Enum, ScopeDef, Semantics, Trait, Type};
7use ra_ide_db::RootDatabase; 7use ra_ide_db::RootDatabase;
8use ra_syntax::{ 8use ra_syntax::{
9 ast::{self, make, NameOwner}, 9 ast::{self, make, NameOwner},
10 AstNode, SyntaxNode, T, 10 AstNode,
11 SyntaxKind::*,
12 SyntaxNode, TextSize, T,
11}; 13};
12use rustc_hash::FxHashSet; 14use rustc_hash::FxHashSet;
13 15
@@ -120,6 +122,13 @@ pub(crate) fn resolve_target_trait(
120 } 122 }
121} 123}
122 124
125pub(crate) fn vis_offset(node: &SyntaxNode) -> TextSize {
126 node.children_with_tokens()
127 .find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR))
128 .map(|it| it.text_range().start())
129 .unwrap_or_else(|| node.text_range().start())
130}
131
123pub(crate) fn invert_boolean_expression(expr: ast::Expr) -> ast::Expr { 132pub(crate) fn invert_boolean_expression(expr: ast::Expr) -> ast::Expr {
124 if let Some(expr) = invert_special_case(&expr) { 133 if let Some(expr) = invert_special_case(&expr) {
125 return expr; 134 return expr;