From e75e2ae5b6b6b1364368ceb3d4081b6508b2f001 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Sun, 28 Jun 2020 04:02:03 +0300 Subject: Simlify with matches!() --- crates/ra_assists/src/handlers/fix_visibility.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'crates/ra_assists/src/handlers/fix_visibility.rs') diff --git a/crates/ra_assists/src/handlers/fix_visibility.rs b/crates/ra_assists/src/handlers/fix_visibility.rs index 54601d1f3..02763c5b9 100644 --- a/crates/ra_assists/src/handlers/fix_visibility.rs +++ b/crates/ra_assists/src/handlers/fix_visibility.rs @@ -179,11 +179,7 @@ fn target_data_for_def( fn vis_offset(node: &SyntaxNode) -> TextSize { node.children_with_tokens() - .skip_while(|it| match it.kind() { - WHITESPACE | COMMENT | ATTR => true, - _ => false, - }) - .next() + .find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR)) .map(|it| it.text_range().start()) .unwrap_or_else(|| node.text_range().start()) } -- cgit v1.2.3 From 503f9498cd469c6467250c02bd8f6dbce973dd57 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Mon, 29 Jun 2020 01:18:50 +0300 Subject: Follow matklad suggestions - Move vis_offset() to utils.rs - Shorten explicit ra_syntax::ast -> ast - Undo refactoring exhaustive pattern to non-exhaustive --- crates/ra_assists/src/handlers/fix_visibility.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'crates/ra_assists/src/handlers/fix_visibility.rs') 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::{ SyntaxNode, TextRange, TextSize, }; -use crate::{AssistContext, AssistId, Assists}; +use crate::{utils::vis_offset, AssistContext, AssistId, Assists}; // FIXME: this really should be a fix for diagnostic, rather than an assist. @@ -177,13 +177,6 @@ fn target_data_for_def( Some((offset, target, target_file, target_name)) } -fn vis_offset(node: &SyntaxNode) -> TextSize { - node.children_with_tokens() - .find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR)) - .map(|it| it.text_range().start()) - .unwrap_or_else(|| node.text_range().start()) -} - #[cfg(test)] mod tests { use crate::tests::{check_assist, check_assist_not_applicable}; -- cgit v1.2.3 From 36128c170d9d938cfcc52bc851aaed1fab6a2ad9 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Mon, 29 Jun 2020 01:23:39 +0300 Subject: Get rid of unused imports --- crates/ra_assists/src/handlers/fix_visibility.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'crates/ra_assists/src/handlers/fix_visibility.rs') diff --git a/crates/ra_assists/src/handlers/fix_visibility.rs b/crates/ra_assists/src/handlers/fix_visibility.rs index 468f9a77f..19d4dac5e 100644 --- a/crates/ra_assists/src/handlers/fix_visibility.rs +++ b/crates/ra_assists/src/handlers/fix_visibility.rs @@ -1,10 +1,6 @@ use hir::{db::HirDatabase, HasSource, HasVisibility, PathResolution}; use ra_db::FileId; -use ra_syntax::{ - ast, AstNode, - SyntaxKind::{ATTR, COMMENT, WHITESPACE}, - SyntaxNode, TextRange, TextSize, -}; +use ra_syntax::{ast, AstNode, TextRange, TextSize}; use crate::{utils::vis_offset, AssistContext, AssistId, Assists}; -- cgit v1.2.3