diff options
Diffstat (limited to 'crates/ra_ide')
-rw-r--r-- | crates/ra_ide/src/completion/complete_fn_param.rs | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/crates/ra_ide/src/completion/complete_fn_param.rs b/crates/ra_ide/src/completion/complete_fn_param.rs index ee91bbdea..db2abb4f1 100644 --- a/crates/ra_ide/src/completion/complete_fn_param.rs +++ b/crates/ra_ide/src/completion/complete_fn_param.rs | |||
@@ -18,16 +18,12 @@ 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 | let me = ctx.token.ancestors().find_map(ast::FnDef::cast); |
22 | for node in ctx.token.parent().ancestors() { | 22 | for node in ctx.token.parent().ancestors() { |
23 | let items = match_ast! { | 23 | let items = match_ast! { |
24 | match node { | 24 | match node { |
25 | ast::SourceFile(it) => it.items(), | 25 | ast::SourceFile(it) => it.items(), |
26 | ast::ItemList(it) => it.items(), | 26 | ast::ItemList(it) => it.items(), |
27 | ast::FnDef(it) => { | ||
28 | me = Some(it); | ||
29 | continue; | ||
30 | }, | ||
31 | _ => continue, | 27 | _ => continue, |
32 | } | 28 | } |
33 | }; | 29 | }; |
@@ -43,6 +39,7 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext) | |||
43 | } | 39 | } |
44 | } | 40 | } |
45 | } | 41 | } |
42 | |||
46 | params | 43 | params |
47 | .into_iter() | 44 | .into_iter() |
48 | .filter_map(|(label, param)| { | 45 | .filter_map(|(label, param)| { |
@@ -111,4 +108,18 @@ pub(crate) trait SourceRoot { | |||
111 | "#]], | 108 | "#]], |
112 | ); | 109 | ); |
113 | } | 110 | } |
111 | |||
112 | #[test] | ||
113 | fn completes_param_in_inner_function() { | ||
114 | check( | ||
115 | r#" | ||
116 | fn outer(text: String) { | ||
117 | fn inner(<|>) | ||
118 | } | ||
119 | "#, | ||
120 | expect![[r#" | ||
121 | bn text: String | ||
122 | "#]], | ||
123 | ) | ||
124 | } | ||
114 | } | 125 | } |