diff --git a/crates/ra_ide/src/completion/complete_fn_param.rs b/crates/ra_ide/src/completion/complete_fn_param.rs index ee91bbdeacb..db2abb4f136 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) } let mut params = FxHashMap::default(); - let mut me = None; + let me = ctx.token.ancestors().find_map(ast::FnDef::cast); for node in ctx.token.parent().ancestors() { let items = match_ast! { match node { ast::SourceFile(it) => it.items(), ast::ItemList(it) => it.items(), - ast::FnDef(it) => { - me = Some(it); - continue; - }, _ => continue, } }; @@ -43,6 +39,7 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext) } } } + params .into_iter() .filter_map(|(label, param)| { @@ -111,4 +108,18 @@ pub fn syntax(&self, file<|>) "#]], ); } + + #[test] + fn completes_param_in_inner_function() { + check( + r#" +fn outer(text: String) { + fn inner(<|>) +} +"#, + expect![[r#" + bn text: String + "#]], + ) + } }