From 51dd06566e65f17f76db7a22fa3ee4d0ab9d33bb Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 10 Jul 2020 16:29:14 +0200 Subject: Complete params in nested fns --- crates/ra_ide/src/completion/complete_fn_param.rs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'crates/ra_ide') 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) } 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(crate) trait SourceRoot { "#]], ); } + + #[test] + fn completes_param_in_inner_function() { + check( + r#" +fn outer(text: String) { + fn inner(<|>) +} +"#, + expect![[r#" + bn text: String + "#]], + ) + } } -- cgit v1.2.3