diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-07-10 15:29:37 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-07-10 15:29:37 +0100 |
commit | 5a195001d79995a6336988e18a2b78052917a02e (patch) | |
tree | a471035bd615ca2038001b07fd1e974bdae8e96f /crates | |
parent | 31f2b9fbaa52d01b9251b5da74381576fe24d3b4 (diff) | |
parent | 51dd06566e65f17f76db7a22fa3ee4d0ab9d33bb (diff) |
Merge #5295
5295: Complete params in nested fns r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-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 | } |