From 0ed27c388adca887cda3d8141efaf974e90a5958 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 9 Apr 2020 23:02:10 +0200 Subject: Drop needless trait --- crates/ra_ide/src/completion/complete_fn_param.rs | 30 ++++++++++++----------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/completion/complete_fn_param.rs b/crates/ra_ide/src/completion/complete_fn_param.rs index 62ae5ccb4..f84b559fc 100644 --- a/crates/ra_ide/src/completion/complete_fn_param.rs +++ b/crates/ra_ide/src/completion/complete_fn_param.rs @@ -1,6 +1,9 @@ //! FIXME: write short doc here -use ra_syntax::{ast, match_ast, AstNode}; +use ra_syntax::{ + ast::{self, ModuleItemOwner}, + match_ast, AstNode, +}; use rustc_hash::FxHashMap; use crate::completion::{CompletionContext, CompletionItem, CompletionKind, Completions}; @@ -16,11 +19,19 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext) let mut params = FxHashMap::default(); for node in ctx.token.parent().ancestors() { - match_ast! { + let items = match_ast! { match node { - ast::SourceFile(it) => process(it, &mut params), - ast::ItemList(it) => process(it, &mut params), - _ => (), + ast::SourceFile(it) => it.items(), + ast::ItemList(it) => it.items(), + _ => continue, + } + }; + for item in items { + if let ast::ModuleItem::FnDef(func) = item { + func.param_list().into_iter().flat_map(|it| it.params()).for_each(|param| { + let text = param.syntax().text().to_string(); + params.entry(text).or_insert((0, param)).0 += 1; + }) } } } @@ -39,15 +50,6 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext) .lookup_by(lookup) .add_to(acc) }); - - fn process(node: N, params: &mut FxHashMap) { - node.functions().filter_map(|it| it.param_list()).flat_map(|it| it.params()).for_each( - |param| { - let text = param.syntax().text().to_string(); - params.entry(text).or_insert((0, param)).0 += 1; - }, - ) - } } #[cfg(test)] -- cgit v1.2.3 From 30084a56a5731343bd4cec727646a6c55900234f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 9 Apr 2020 23:35:05 +0200 Subject: Simpler acessors for keywords --- crates/ra_ide/src/completion/completion_context.rs | 4 ++-- crates/ra_ide/src/references.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index 0e34d85db..6637afaf7 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs @@ -191,8 +191,8 @@ impl<'a> CompletionContext<'a> { if let Some(bind_pat) = name.syntax().ancestors().find_map(ast::BindPat::cast) { self.is_pat_binding_or_const = true; if bind_pat.at_token().is_some() - || bind_pat.ref_kw_token().is_some() - || bind_pat.mut_kw_token().is_some() + || bind_pat.ref_token().is_some() + || bind_pat.mut_token().is_some() { self.is_pat_binding_or_const = false; } diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index ad6fd50aa..7d0544ff4 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs @@ -152,7 +152,7 @@ fn decl_access(def: &Definition, syntax: &SyntaxNode, range: TextRange) -> Optio if stmt.initializer().is_some() { let pat = stmt.pat()?; if let ast::Pat::BindPat(it) = pat { - if it.mut_kw_token().is_some() { + if it.mut_token().is_some() { return Some(ReferenceAccess::Write); } } -- cgit v1.2.3