diff options
author | Ekaterina Babshukova <[email protected]> | 2019-10-05 15:03:03 +0100 |
---|---|---|
committer | Ekaterina Babshukova <[email protected]> | 2019-10-05 15:03:03 +0100 |
commit | 2fc22901730f35405d2bdfe33f88d7b3c6b14304 (patch) | |
tree | c3565f17b7db1625d3c8311432d0bed258b58ca5 /crates/ra_ide_api/src/completion | |
parent | dbf869b4d2dac09df17609edf6e67c1611b71dc5 (diff) |
replace AST visitors with macro
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 | } |