aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide/src/completion/complete_fn_param.rs30
-rw-r--r--crates/ra_syntax/src/ast/generated/nodes.rs4
-rw-r--r--crates/ra_syntax/src/ast/traits.rs6
3 files changed, 16 insertions, 24 deletions
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 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use ra_syntax::{ast, match_ast, AstNode}; 3use ra_syntax::{
4 ast::{self, ModuleItemOwner},
5 match_ast, AstNode,
6};
4use rustc_hash::FxHashMap; 7use rustc_hash::FxHashMap;
5 8
6use crate::completion::{CompletionContext, CompletionItem, CompletionKind, Completions}; 9use crate::completion::{CompletionContext, CompletionItem, CompletionKind, Completions};
@@ -16,11 +19,19 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
16 19
17 let mut params = FxHashMap::default(); 20 let mut params = FxHashMap::default();
18 for node in ctx.token.parent().ancestors() { 21 for node in ctx.token.parent().ancestors() {
19 match_ast! { 22 let items = match_ast! {
20 match node { 23 match node {
21 ast::SourceFile(it) => process(it, &mut params), 24 ast::SourceFile(it) => it.items(),
22 ast::ItemList(it) => process(it, &mut params), 25 ast::ItemList(it) => it.items(),
23 _ => (), 26 _ => continue,
27 }
28 };
29 for item in items {
30 if let ast::ModuleItem::FnDef(func) = item {
31 func.param_list().into_iter().flat_map(|it| it.params()).for_each(|param| {
32 let text = param.syntax().text().to_string();
33 params.entry(text).or_insert((0, param)).0 += 1;
34 })
24 } 35 }
25 } 36 }
26 } 37 }
@@ -39,15 +50,6 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
39 .lookup_by(lookup) 50 .lookup_by(lookup)
40 .add_to(acc) 51 .add_to(acc)
41 }); 52 });
42
43 fn process<N: ast::FnDefOwner>(node: N, params: &mut FxHashMap<String, (u32, ast::Param)>) {
44 node.functions().filter_map(|it| it.param_list()).flat_map(|it| it.params()).for_each(
45 |param| {
46 let text = param.syntax().text().to_string();
47 params.entry(text).or_insert((0, param)).0 += 1;
48 },
49 )
50 }
51} 53}
52 54
53#[cfg(test)] 55#[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 {
22 fn syntax(&self) -> &SyntaxNode { &self.syntax } 22 fn syntax(&self) -> &SyntaxNode { &self.syntax }
23} 23}
24impl ast::ModuleItemOwner for SourceFile {} 24impl ast::ModuleItemOwner for SourceFile {}
25impl ast::FnDefOwner for SourceFile {}
26impl ast::AttrsOwner for SourceFile {} 25impl ast::AttrsOwner for SourceFile {}
27impl SourceFile { 26impl SourceFile {
28 pub fn modules(&self) -> AstChildren<Module> { support::children(&self.syntax) } 27 pub fn modules(&self) -> AstChildren<Module> { support::children(&self.syntax) }
@@ -344,7 +343,6 @@ impl AstNode for ItemList {
344 } 343 }
345 fn syntax(&self) -> &SyntaxNode { &self.syntax } 344 fn syntax(&self) -> &SyntaxNode { &self.syntax }
346} 345}
347impl ast::FnDefOwner for ItemList {}
348impl ast::ModuleItemOwner for ItemList {} 346impl ast::ModuleItemOwner for ItemList {}
349impl ItemList { 347impl ItemList {
350 pub fn l_curly_token(&self) -> Option<LCurly> { support::token(&self.syntax) } 348 pub fn l_curly_token(&self) -> Option<LCurly> { support::token(&self.syntax) }
@@ -2512,7 +2510,6 @@ impl AstNode for MacroItems {
2512 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2510 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2513} 2511}
2514impl ast::ModuleItemOwner for MacroItems {} 2512impl ast::ModuleItemOwner for MacroItems {}
2515impl ast::FnDefOwner for MacroItems {}
2516impl MacroItems {} 2513impl MacroItems {}
2517#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2514#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2518pub struct MacroStmts { 2515pub struct MacroStmts {
@@ -2548,7 +2545,6 @@ impl AstNode for ExternItemList {
2548 } 2545 }
2549 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2546 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2550} 2547}
2551impl ast::FnDefOwner for ExternItemList {}
2552impl ast::ModuleItemOwner for ExternItemList {} 2548impl ast::ModuleItemOwner for ExternItemList {}
2553impl ExternItemList { 2549impl ExternItemList {
2554 pub fn l_curly_token(&self) -> Option<LCurly> { support::token(&self.syntax) } 2550 pub fn l_curly_token(&self) -> Option<LCurly> { 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 {
43 } 43 }
44} 44}
45 45
46pub trait FnDefOwner: AstNode {
47 fn functions(&self) -> AstChildren<ast::FnDef> {
48 support::children(self.syntax())
49 }
50}
51
52pub trait ModuleItemOwner: AstNode { 46pub trait ModuleItemOwner: AstNode {
53 fn items(&self) -> AstChildren<ast::ModuleItem> { 47 fn items(&self) -> AstChildren<ast::ModuleItem> {
54 support::children(self.syntax()) 48 support::children(self.syntax())