diff options
author | Aleksey Kladov <[email protected]> | 2020-07-10 15:07:12 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-07-10 15:07:12 +0100 |
commit | d02aabe633b6da6748e9911219b46c6ff206595d (patch) | |
tree | 27fd90c9c6a788cf058c4a6f65b4a43b0e8db1c3 /crates/ra_ide | |
parent | 74d376763c767ce6e1358c794880f325486a565f (diff) |
Complete parameters more aggressively
Diffstat (limited to 'crates/ra_ide')
-rw-r--r-- | crates/ra_ide/src/completion/complete_fn_param.rs | 21 |
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 | ||
3 | use ra_syntax::{ | 3 | use 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#" |
85 | fn foo(file_id: FileId) {} | 89 | fn foo(file_id: FileId) {} |
86 | fn bar(file_id: FileId) {} | ||
87 | fn baz(file<|>, x: i32) {} | 90 | fn baz(file<|>, x: i32) {} |
88 | "#, | 91 | "#, |
89 | expect![[r#" | 92 | expect![[r#" |