From d323c81d5cc6a198239285abcede2166181d8f39 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 2 Oct 2018 18:02:57 +0300 Subject: make ancestors and descendants inherent --- crates/ra_editor/src/code_actions.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'crates/ra_editor/src/code_actions.rs') diff --git a/crates/ra_editor/src/code_actions.rs b/crates/ra_editor/src/code_actions.rs index 83f7956d2..b0f0d8f1d 100644 --- a/crates/ra_editor/src/code_actions.rs +++ b/crates/ra_editor/src/code_actions.rs @@ -9,7 +9,6 @@ use ra_syntax::{ Direction, siblings, find_leaf_at_offset, find_covering_node, - ancestors, }, }; @@ -101,8 +100,8 @@ pub fn add_impl<'a>(file: &'a File, offset: TextUnit) -> Option pub fn introduce_variable<'a>(file: &'a File, range: TextRange) -> Option LocalEdit + 'a> { let node = find_covering_node(file.syntax(), range); - let expr = ancestors(node).filter_map(ast::Expr::cast).next()?; - let anchor_stmt = ancestors(expr.syntax()).filter_map(ast::Stmt::cast).next()?; + let expr = node.ancestors().filter_map(ast::Expr::cast).next()?; + let anchor_stmt = expr.syntax().ancestors().filter_map(ast::Stmt::cast).next()?; let indent = anchor_stmt.syntax().prev_sibling()?; if indent.kind() != WHITESPACE { return None; -- cgit v1.2.3 From 1a2a8dec14ec04ea8eeccae99fd885e7a280e45b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 2 Oct 2018 18:14:33 +0300 Subject: Make siblings an inherent method --- crates/ra_editor/src/code_actions.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'crates/ra_editor/src/code_actions.rs') diff --git a/crates/ra_editor/src/code_actions.rs b/crates/ra_editor/src/code_actions.rs index b0f0d8f1d..216d592ff 100644 --- a/crates/ra_editor/src/code_actions.rs +++ b/crates/ra_editor/src/code_actions.rs @@ -1,12 +1,11 @@ use join_to_string::join; use ra_syntax::{ - File, TextUnit, TextRange, + File, TextUnit, TextRange, Direction, ast::{self, AstNode, AttrsOwner, TypeParamsOwner, NameOwner}, SyntaxKind::{COMMA, WHITESPACE}, SyntaxNodeRef, algo::{ - Direction, siblings, find_leaf_at_offset, find_covering_node, }, @@ -24,12 +23,12 @@ pub fn flip_comma<'a>(file: &'a File, offset: TextUnit) -> Option(file: &'a File, range: TextRange) -> Option Option { - siblings(node, direction) + node.siblings(direction) .skip(1) .find(|node| !node.kind().is_trivia()) } -- cgit v1.2.3