fix: lookup

This commit is contained in:
rainy-me 2022-04-22 00:07:42 +09:00
parent a58f7acc97
commit 8f8f20fda5
2 changed files with 26 additions and 11 deletions

View file

@ -30,11 +30,10 @@ pub(crate) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
let mk_item = |label: &str, range: TextRange| {
CompletionItem::new(CompletionItemKind::Binding, range, label)
};
let mut item = match &comma_wrapper {
Some((fmt, range)) => mk_item(&fmt(label), *range),
None => mk_item(label, ctx.source_range()),
let item = match &comma_wrapper {
Some((fmt, range, lookup)) => mk_item(&fmt(label), *range).lookup_by(lookup).to_owned(),
None => mk_item(label, ctx.source_range()).lookup_by(lookup).to_owned(),
};
item.lookup_by(lookup);
item.add_to(acc)
};
@ -162,7 +161,7 @@ fn should_add_self_completions(ctx: &CompletionContext, param_list: &ast::ParamL
inside_impl && no_params
}
fn comma_wrapper(ctx: &CompletionContext) -> Option<(impl Fn(&str) -> String, TextRange)> {
fn comma_wrapper(ctx: &CompletionContext) -> Option<(impl Fn(&str) -> String, TextRange, String)> {
let param = ctx.token.ancestors().find(|node| node.kind() == SyntaxKind::PARAM)?;
let next_token_kind = {
@ -184,5 +183,9 @@ fn comma_wrapper(ctx: &CompletionContext) -> Option<(impl Fn(&str) -> String, Te
matches!(prev_token_kind, SyntaxKind::COMMA | SyntaxKind::L_PAREN | SyntaxKind::PIPE);
let leading = if has_leading_comma { "" } else { ", " };
Some((move |label: &_| (format!("{}{}{}", leading, label, trailing)), param.text_range()))
Some((
move |label: &_| (format!("{}{}{}", leading, label, trailing)),
param.text_range(),
format!("{}{}", leading, param.text()),
))
}

View file

@ -570,7 +570,7 @@ fn main() {
fn complete_fn_param() {
// has mut kw
check_edit(
"mut bar",
"mut ba",
r#"
fn f(foo: (), mut bar: u32) {}
fn g(foo: (), mut ba$0)
@ -583,7 +583,7 @@ fn g(foo: (), mut bar: u32)
// has type param
check_edit(
"mut bar",
"mut ba: u32",
r#"
fn g(foo: (), mut ba$0: u32)
fn f(foo: (), mut bar: u32) {}
@ -599,7 +599,7 @@ fn f(foo: (), mut bar: u32) {}
fn complete_fn_mut_param_add_comma() {
// add leading and trailing comma
check_edit(
"mut bar",
", mut ba",
r#"
fn f(foo: (), mut bar: u32) {}
fn g(foo: ()mut ba$0 baz: ())
@ -614,7 +614,7 @@ fn g(foo: (), mut bar: u32, baz: ())
#[test]
fn complete_fn_mut_param_has_attribute() {
check_edit(
"mut bar",
"mut ba",
r#"
fn f(foo: (), #[baz = "qux"] mut bar: u32) {}
fn g(foo: (), mut ba$0)
@ -626,7 +626,7 @@ fn g(foo: (), #[baz = "qux"] mut bar: u32)
);
check_edit(
"mut bar",
r#"#[baz = "qux"] mut ba"#,
r#"
fn f(foo: (), #[baz = "qux"] mut bar: u32) {}
fn g(foo: (), #[baz = "qux"] mut ba$0)
@ -634,6 +634,18 @@ fn g(foo: (), #[baz = "qux"] mut ba$0)
r#"
fn f(foo: (), #[baz = "qux"] mut bar: u32) {}
fn g(foo: (), #[baz = "qux"] mut bar: u32)
"#,
);
check_edit(
r#", #[baz = "qux"] mut ba"#,
r#"
fn f(foo: (), #[baz = "qux"] mut bar: u32) {}
fn g(foo: ()#[baz = "qux"] mut ba$0)
"#,
r#"
fn f(foo: (), #[baz = "qux"] mut bar: u32) {}
fn g(foo: (), #[baz = "qux"] mut bar: u32)
"#,
);
}