aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide')
-rw-r--r--crates/ra_ide/src/completion/complete_fn_param.rs21
1 files changed, 12 insertions, 9 deletions
diff --git a/crates/ra_ide/src/completion/complete_fn_param.rs b/crates/ra_ide/src/completion/complete_fn_param.rs
index 107888353..ee91bbdea 100644
--- a/crates/ra_ide/src/completion/complete_fn_param.rs
+++ b/crates/ra_ide/src/completion/complete_fn_param.rs
@@ -1,4 +1,4 @@
1//! FIXME: write short doc here 1//! See `complete_fn_param`.
2 2
3use ra_syntax::{ 3use ra_syntax::{
4 ast::{self, ModuleItemOwner}, 4 ast::{self, ModuleItemOwner},
@@ -18,32 +18,36 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
18 } 18 }
19 19
20 let mut params = FxHashMap::default(); 20 let mut params = FxHashMap::default();
21 let mut me = None;
21 for node in ctx.token.parent().ancestors() { 22 for node in ctx.token.parent().ancestors() {
22 let items = match_ast! { 23 let items = match_ast! {
23 match node { 24 match node {
24 ast::SourceFile(it) => it.items(), 25 ast::SourceFile(it) => it.items(),
25 ast::ItemList(it) => it.items(), 26 ast::ItemList(it) => it.items(),
27 ast::FnDef(it) => {
28 me = Some(it);
29 continue;
30 },
26 _ => continue, 31 _ => continue,
27 } 32 }
28 }; 33 };
29 for item in items { 34 for item in items {
30 if let ast::ModuleItem::FnDef(func) = item { 35 if let ast::ModuleItem::FnDef(func) = item {
36 if Some(&func) == me.as_ref() {
37 continue;
38 }
31 func.param_list().into_iter().flat_map(|it| it.params()).for_each(|param| { 39 func.param_list().into_iter().flat_map(|it| it.params()).for_each(|param| {
32 let text = param.syntax().text().to_string(); 40 let text = param.syntax().text().to_string();
33 params.entry(text).or_insert((0, param)).0 += 1; 41 params.entry(text).or_insert(param);
34 }) 42 })
35 } 43 }
36 } 44 }
37 } 45 }
38 params 46 params
39 .into_iter() 47 .into_iter()
40 .filter_map(|(label, (count, param))| { 48 .filter_map(|(label, param)| {
41 let lookup = param.pat()?.syntax().text().to_string(); 49 let lookup = param.pat()?.syntax().text().to_string();
42 if count < 2 { 50 Some((label, lookup))
43 None
44 } else {
45 Some((label, lookup))
46 }
47 }) 51 })
48 .for_each(|(label, lookup)| { 52 .for_each(|(label, lookup)| {
49 CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label) 53 CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label)
@@ -83,7 +87,6 @@ fn baz(file<|>) {}
83 check( 87 check(
84 r#" 88 r#"
85fn foo(file_id: FileId) {} 89fn foo(file_id: FileId) {}
86fn bar(file_id: FileId) {}
87fn baz(file<|>, x: i32) {} 90fn baz(file<|>, x: i32) {}
88"#, 91"#,
89 expect![[r#" 92 expect![[r#"