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 ++++++++++++----------- crates/ra_syntax/src/ast/generated/nodes.rs | 4 --- crates/ra_syntax/src/ast/traits.rs | 6 ----- 3 files changed, 16 insertions(+), 24 deletions(-) (limited to 'crates') 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)] diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index bcbfd1129..3b820507d 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -22,7 +22,6 @@ impl AstNode for SourceFile { fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl ast::ModuleItemOwner for SourceFile {} -impl ast::FnDefOwner for SourceFile {} impl ast::AttrsOwner for SourceFile {} impl SourceFile { pub fn modules(&self) -> AstChildren { support::children(&self.syntax) } @@ -344,7 +343,6 @@ impl AstNode for ItemList { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl ast::FnDefOwner for ItemList {} impl ast::ModuleItemOwner for ItemList {} impl ItemList { pub fn l_curly_token(&self) -> Option { support::token(&self.syntax) } @@ -2512,7 +2510,6 @@ impl AstNode for MacroItems { fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl ast::ModuleItemOwner for MacroItems {} -impl ast::FnDefOwner for MacroItems {} impl MacroItems {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct MacroStmts { @@ -2548,7 +2545,6 @@ impl AstNode for ExternItemList { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl ast::FnDefOwner for ExternItemList {} impl ast::ModuleItemOwner for ExternItemList {} impl ExternItemList { pub fn l_curly_token(&self) -> Option { support::token(&self.syntax) } diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs index f6c786e44..f0b54cf29 100644 --- a/crates/ra_syntax/src/ast/traits.rs +++ b/crates/ra_syntax/src/ast/traits.rs @@ -43,12 +43,6 @@ pub trait ArgListOwner: AstNode { } } -pub trait FnDefOwner: AstNode { - fn functions(&self) -> AstChildren { - support::children(self.syntax()) - } -} - pub trait ModuleItemOwner: AstNode { fn items(&self) -> AstChildren { support::children(self.syntax()) -- cgit v1.2.3