5295: Complete params in nested fns r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-07-10 14:29:37 +00:00 committed by GitHub
commit 5a195001d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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
"#]],
)
}
}