diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-10-02 16:51:39 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-10-02 16:51:39 +0100 |
commit | 248ee0c3fe333f9180f8c9d9dfd4efcc6886b5bc (patch) | |
tree | f94bb3a8bd47e3612ef29e815532c07d7871fa0f /crates/ra_editor/src/completion.rs | |
parent | 7ffc114dab6d1e25ead195a5937cd4f9ca51ef2c (diff) | |
parent | 1a2a8dec14ec04ea8eeccae99fd885e7a280e45b (diff) |
Merge #90
90: Inherent traversal r=matklad a=matklad
bors r+
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_editor/src/completion.rs')
-rw-r--r-- | crates/ra_editor/src/completion.rs | 13 |
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 | ||
93 | fn param_completions(ctx: SyntaxNodeRef, acc: &mut Vec<CompletionItem>) { | 92 | fn 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 | ||
125 | fn is_node<'a, N: AstNode<'a>>(node: SyntaxNodeRef<'a>) -> bool { | 124 | fn 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 | ||
154 | fn is_in_loop_body(name_ref: ast::NameRef) -> bool { | 153 | fn 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 | ||
173 | fn complete_return(fn_def: ast::FnDef, name_ref: ast::NameRef) -> Option<CompletionItem> { | 172 | fn 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 | }; |