From 8c2c1bf9eb1496adeaa647066c96d0e7d71a1a8a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 27 Dec 2018 13:35:08 +0300 Subject: check edits in diagnostics --- crates/ra_editor/src/lib.rs | 48 ++++++++++++++++++++++++------------------ crates/ra_editor/src/typing.rs | 16 +++----------- 2 files changed, 30 insertions(+), 34 deletions(-) (limited to 'crates/ra_editor/src') diff --git a/crates/ra_editor/src/lib.rs b/crates/ra_editor/src/lib.rs index dcf8be5a7..a8c68e79e 100644 --- a/crates/ra_editor/src/lib.rs +++ b/crates/ra_editor/src/lib.rs @@ -24,6 +24,7 @@ use ra_syntax::{ SyntaxKind::{self, *}, SyntaxNodeRef, TextRange, TextUnit, }; +use itertools::Itertools; #[derive(Debug)] pub struct HighlightedRange { @@ -126,10 +127,8 @@ fn check_unnecessary_braces_in_use_statement(file: &SourceFileNode) -> Vec Option { fn join_single_use_tree(edit: &mut TextEditBuilder, node: SyntaxNodeRef) -> Option<()> { let use_tree_list = ast::UseTreeList::cast(node.parent()?)?; - let tree = single_use_tree(use_tree_list)?; + let (tree,) = use_tree_list.use_trees().collect_tuple()?; edit.replace( use_tree_list.syntax().range(), tree.syntax().text().to_string(), @@ -254,15 +253,6 @@ fn join_single_use_tree(edit: &mut TextEditBuilder, node: SyntaxNodeRef) -> Opti Some(()) } -fn single_use_tree(tree_list: ast::UseTreeList) -> Option { - let sub_use_trees = tree_list.use_trees().count(); - if sub_use_trees != 1 { - return None; - } - - tree_list.use_trees().next() -} - fn compute_ws(left: SyntaxNodeRef, right: SyntaxNodeRef) -> &'static str { match left.kind() { L_PAREN | L_BRACK => return "", -- cgit v1.2.3