From 2fc22901730f35405d2bdfe33f88d7b3c6b14304 Mon Sep 17 00:00:00 2001 From: Ekaterina Babshukova Date: Sat, 5 Oct 2019 17:03:03 +0300 Subject: replace AST visitors with macro --- crates/ra_ide_api/src/completion/complete_fn_param.rs | 16 ++++++++-------- crates/ra_ide_api/src/completion/complete_keyword.rs | 18 ++++++++++-------- 2 files changed, 18 insertions(+), 16 deletions(-) (limited to 'crates/ra_ide_api/src/completion') 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 @@ //! FIXME: write short doc here -use ra_syntax::{ - algo::visit::{visitor_ctx, VisitorCtx}, - ast, AstNode, -}; +use ra_syntax::{ast, match_ast, AstNode}; use rustc_hash::FxHashMap; use crate::completion::{CompletionContext, CompletionItem, CompletionKind, Completions}; @@ -19,10 +16,13 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext) let mut params = FxHashMap::default(); for node in ctx.token.parent().ancestors() { - let _ = visitor_ctx(&mut params) - .visit::(process) - .visit::(process) - .accept(&node); + match_ast! { + match node { + ast::SourceFile(it) => { process(it, &mut params) }, + ast::ItemList(it) => { process(it, &mut params) }, + _ => (), + } + } } params .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 @@ //! FIXME: write short doc here use ra_syntax::{ - algo::visit::{visitor, Visitor}, ast::{self, LoopBodyOwner}, - AstNode, + match_ast, AstNode, SyntaxKind::*, SyntaxToken, }; @@ -84,12 +83,15 @@ fn is_in_loop_body(leaf: &SyntaxToken) -> bool { if node.kind() == FN_DEF || node.kind() == LAMBDA_EXPR { break; } - let loop_body = visitor() - .visit::(|it| it.loop_body()) - .visit::(|it| it.loop_body()) - .visit::(|it| it.loop_body()) - .accept(&node); - if let Some(Some(body)) = loop_body { + let loop_body = match_ast! { + match node { + ast::ForExpr(it) => { it.loop_body() }, + ast::WhileExpr(it) => { it.loop_body() }, + ast::LoopExpr(it) => { it.loop_body() }, + _ => None, + } + }; + if let Some(body) = loop_body { if leaf.text_range().is_subrange(&body.syntax().text_range()) { return true; } -- cgit v1.2.3