aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_editor/src/completion.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-10-02 16:02:57 +0100
committerAleksey Kladov <[email protected]>2018-10-02 16:02:57 +0100
commitd323c81d5cc6a198239285abcede2166181d8f39 (patch)
tree02c64a01b14d893df439a9e90797db6d58c5a54d /crates/ra_editor/src/completion.rs
parentdccaa5e45e9baaa2d286353a7499a89af1669e42 (diff)
make ancestors and descendants inherent
Diffstat (limited to 'crates/ra_editor/src/completion.rs')
-rw-r--r--crates/ra_editor/src/completion.rs13
1 files changed, 6 insertions, 7 deletions
diff --git a/crates/ra_editor/src/completion.rs b/crates/ra_editor/src/completion.rs
index ff9de20d3..62a63fb04 100644
--- a/crates/ra_editor/src/completion.rs
+++ b/crates/ra_editor/src/completion.rs
@@ -4,7 +4,6 @@ use ra_syntax::{
4 File, TextUnit, AstNode, SyntaxNodeRef, SyntaxKind::*, 4 File, TextUnit, AstNode, SyntaxNodeRef, SyntaxKind::*,
5 ast::{self, LoopBodyOwner, ModuleItemOwner}, 5 ast::{self, LoopBodyOwner, ModuleItemOwner},
6 algo::{ 6 algo::{
7 ancestors,
8 visit::{visitor, Visitor, visitor_ctx, VisitorCtx}, 7 visit::{visitor, Visitor, visitor_ctx, VisitorCtx},
9 }, 8 },
10 text_utils::is_subrange, 9 text_utils::is_subrange,
@@ -59,7 +58,7 @@ fn complete_name_ref(file: &File, name_ref: ast::NameRef, acc: &mut Vec<Completi
59 return; 58 return;
60 } 59 }
61 let mut visited_fn = false; 60 let mut visited_fn = false;
62 for node in ancestors(name_ref.syntax()) { 61 for node in name_ref.syntax().ancestors() {
63 if let Some(items) = visitor() 62 if let Some(items) = visitor()
64 .visit::<ast::Root, _>(|it| Some(it.items())) 63 .visit::<ast::Root, _>(|it| Some(it.items()))
65 .visit::<ast::Module, _>(|it| Some(it.item_list()?.items())) 64 .visit::<ast::Module, _>(|it| Some(it.item_list()?.items()))
@@ -92,7 +91,7 @@ fn complete_name_ref(file: &File, name_ref: ast::NameRef, acc: &mut Vec<Completi
92 91
93fn param_completions(ctx: SyntaxNodeRef, acc: &mut Vec<CompletionItem>) { 92fn param_completions(ctx: SyntaxNodeRef, acc: &mut Vec<CompletionItem>) {
94 let mut params = HashMap::new(); 93 let mut params = HashMap::new();
95 for node in ancestors(ctx) { 94 for node in ctx.ancestors() {
96 let _ = visitor_ctx(&mut params) 95 let _ = visitor_ctx(&mut params)
97 .visit::<ast::Root, _>(process) 96 .visit::<ast::Root, _>(process)
98 .visit::<ast::ItemList, _>(process) 97 .visit::<ast::ItemList, _>(process)
@@ -123,7 +122,7 @@ fn param_completions(ctx: SyntaxNodeRef, acc: &mut Vec<CompletionItem>) {
123} 122}
124 123
125fn is_node<'a, N: AstNode<'a>>(node: SyntaxNodeRef<'a>) -> bool { 124fn is_node<'a, N: AstNode<'a>>(node: SyntaxNodeRef<'a>) -> bool {
126 match ancestors(node).filter_map(N::cast).next() { 125 match node.ancestors().filter_map(N::cast).next() {
127 None => false, 126 None => false,
128 Some(n) => n.syntax().range() == node.range(), 127 Some(n) => n.syntax().range() == node.range(),
129 } 128 }
@@ -152,7 +151,7 @@ fn complete_expr_keywords(file: &File, fn_def: ast::FnDef, name_ref: ast::NameRe
152} 151}
153 152
154fn is_in_loop_body(name_ref: ast::NameRef) -> bool { 153fn is_in_loop_body(name_ref: ast::NameRef) -> bool {
155 for node in ancestors(name_ref.syntax()) { 154 for node in name_ref.syntax().ancestors() {
156 if node.kind() == FN_DEF || node.kind() == LAMBDA_EXPR { 155 if node.kind() == FN_DEF || node.kind() == LAMBDA_EXPR {
157 break; 156 break;
158 } 157 }
@@ -171,7 +170,7 @@ fn is_in_loop_body(name_ref: ast::NameRef) -> bool {
171} 170}
172 171
173fn complete_return(fn_def: ast::FnDef, name_ref: ast::NameRef) -> Option<CompletionItem> { 172fn complete_return(fn_def: ast::FnDef, name_ref: ast::NameRef) -> Option<CompletionItem> {
174 // let is_last_in_block = ancestors(name_ref.syntax()).filter_map(ast::Expr::cast) 173 // let is_last_in_block = name_ref.syntax().ancestors().filter_map(ast::Expr::cast)
175 // .next() 174 // .next()
176 // .and_then(|it| it.syntax().parent()) 175 // .and_then(|it| it.syntax().parent())
177 // .and_then(ast::Block::cast) 176 // .and_then(ast::Block::cast)
@@ -181,7 +180,7 @@ fn complete_return(fn_def: ast::FnDef, name_ref: ast::NameRef) -> Option<Complet
181 // return None; 180 // return None;
182 // } 181 // }
183 182
184 let is_stmt = match ancestors(name_ref.syntax()).filter_map(ast::ExprStmt::cast).next() { 183 let is_stmt = match name_ref.syntax().ancestors().filter_map(ast::ExprStmt::cast).next() {
185 None => false, 184 None => false,
186 Some(expr_stmt) => expr_stmt.syntax().range() == name_ref.syntax().range() 185 Some(expr_stmt) => expr_stmt.syntax().range() == name_ref.syntax().range()
187 }; 186 };