diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-10-05 15:54:25 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-10-05 15:54:25 +0100 |
commit | d3872964f88a0d751c428c150bb40d8b4f4c89a9 (patch) | |
tree | 14b7045119a1918118c18857cc094c914284705c /crates/ra_ide_api/src/completion | |
parent | ae6305b90c80eb919cfde985cba66975b6222ed2 (diff) | |
parent | 311dbb854536dd526cdbcadc6d270f9a37e4b816 (diff) |
Merge #1960
1960: Replace AST visitors with macro r=viorina a=viorina
Fixes #1672.
Co-authored-by: Ekaterina Babshukova <[email protected]>
Diffstat (limited to 'crates/ra_ide_api/src/completion')
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_fn_param.rs | 16 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_keyword.rs | 18 |
2 files changed, 18 insertions, 16 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_fn_param.rs b/crates/ra_ide_api/src/completion/complete_fn_param.rs index 844a63f6c..3e936e3ec 100644 --- a/crates/ra_ide_api/src/completion/complete_fn_param.rs +++ b/crates/ra_ide_api/src/completion/complete_fn_param.rs | |||
@@ -1,9 +1,6 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use ra_syntax::{ | 3 | use ra_syntax::{ast, match_ast, AstNode}; |
4 | algo::visit::{visitor_ctx, VisitorCtx}, | ||
5 | ast, AstNode, | ||
6 | }; | ||
7 | use rustc_hash::FxHashMap; | 4 | use rustc_hash::FxHashMap; |
8 | 5 | ||
9 | use crate::completion::{CompletionContext, CompletionItem, CompletionKind, Completions}; | 6 | use crate::completion::{CompletionContext, CompletionItem, CompletionKind, Completions}; |
@@ -19,10 +16,13 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext) | |||
19 | 16 | ||
20 | let mut params = FxHashMap::default(); | 17 | let mut params = FxHashMap::default(); |
21 | for node in ctx.token.parent().ancestors() { | 18 | for node in ctx.token.parent().ancestors() { |
22 | let _ = visitor_ctx(&mut params) | 19 | match_ast! { |
23 | .visit::<ast::SourceFile, _>(process) | 20 | match node { |
24 | .visit::<ast::ItemList, _>(process) | 21 | ast::SourceFile(it) => { process(it, &mut params) }, |
25 | .accept(&node); | 22 | ast::ItemList(it) => { process(it, &mut params) }, |
23 | _ => (), | ||
24 | } | ||
25 | } | ||
26 | } | 26 | } |
27 | params | 27 | params |
28 | .into_iter() | 28 | .into_iter() |
diff --git a/crates/ra_ide_api/src/completion/complete_keyword.rs b/crates/ra_ide_api/src/completion/complete_keyword.rs index 3f121d45c..48c688a08 100644 --- a/crates/ra_ide_api/src/completion/complete_keyword.rs +++ b/crates/ra_ide_api/src/completion/complete_keyword.rs | |||
@@ -1,9 +1,8 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use ra_syntax::{ | 3 | use ra_syntax::{ |
4 | algo::visit::{visitor, Visitor}, | ||
5 | ast::{self, LoopBodyOwner}, | 4 | ast::{self, LoopBodyOwner}, |
6 | AstNode, | 5 | match_ast, AstNode, |
7 | SyntaxKind::*, | 6 | SyntaxKind::*, |
8 | SyntaxToken, | 7 | SyntaxToken, |
9 | }; | 8 | }; |
@@ -84,12 +83,15 @@ fn is_in_loop_body(leaf: &SyntaxToken) -> bool { | |||
84 | if node.kind() == FN_DEF || node.kind() == LAMBDA_EXPR { | 83 | if node.kind() == FN_DEF || node.kind() == LAMBDA_EXPR { |
85 | break; | 84 | break; |
86 | } | 85 | } |
87 | let loop_body = visitor() | 86 | let loop_body = match_ast! { |
88 | .visit::<ast::ForExpr, _>(|it| it.loop_body()) | 87 | match node { |
89 | .visit::<ast::WhileExpr, _>(|it| it.loop_body()) | 88 | ast::ForExpr(it) => { it.loop_body() }, |
90 | .visit::<ast::LoopExpr, _>(|it| it.loop_body()) | 89 | ast::WhileExpr(it) => { it.loop_body() }, |
91 | .accept(&node); | 90 | ast::LoopExpr(it) => { it.loop_body() }, |
92 | if let Some(Some(body)) = loop_body { | 91 | _ => None, |
92 | } | ||
93 | }; | ||
94 | if let Some(body) = loop_body { | ||
93 | if leaf.text_range().is_subrange(&body.syntax().text_range()) { | 95 | if leaf.text_range().is_subrange(&body.syntax().text_range()) { |
94 | return true; | 96 | return true; |
95 | } | 97 | } |