Skip to content

Commit 8f8f20f

Browse files
committed
fix: lookup
1 parent a58f7ac commit 8f8f20f

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

crates/ide_completion/src/completions/fn_param.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@ pub(crate) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
3030
let mk_item = |label: &str, range: TextRange| {
3131
CompletionItem::new(CompletionItemKind::Binding, range, label)
3232
};
33-
let mut item = match &comma_wrapper {
34-
Some((fmt, range)) => mk_item(&fmt(label), *range),
35-
None => mk_item(label, ctx.source_range()),
33+
let item = match &comma_wrapper {
34+
Some((fmt, range, lookup)) => mk_item(&fmt(label), *range).lookup_by(lookup).to_owned(),
35+
None => mk_item(label, ctx.source_range()).lookup_by(lookup).to_owned(),
3636
};
37-
item.lookup_by(lookup);
3837
item.add_to(acc)
3938
};
4039

@@ -162,7 +161,7 @@ fn should_add_self_completions(ctx: &CompletionContext, param_list: &ast::ParamL
162161
inside_impl && no_params
163162
}
164163

165-
fn comma_wrapper(ctx: &CompletionContext) -> Option<(impl Fn(&str) -> String, TextRange)> {
164+
fn comma_wrapper(ctx: &CompletionContext) -> Option<(impl Fn(&str) -> String, TextRange, String)> {
166165
let param = ctx.token.ancestors().find(|node| node.kind() == SyntaxKind::PARAM)?;
167166

168167
let next_token_kind = {
@@ -184,5 +183,9 @@ fn comma_wrapper(ctx: &CompletionContext) -> Option<(impl Fn(&str) -> String, Te
184183
matches!(prev_token_kind, SyntaxKind::COMMA | SyntaxKind::L_PAREN | SyntaxKind::PIPE);
185184
let leading = if has_leading_comma { "" } else { ", " };
186185

187-
Some((move |label: &_| (format!("{}{}{}", leading, label, trailing)), param.text_range()))
186+
Some((
187+
move |label: &_| (format!("{}{}{}", leading, label, trailing)),
188+
param.text_range(),
189+
format!("{}{}", leading, param.text()),
190+
))
188191
}

crates/ide_completion/src/render/function.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ fn main() {
570570
fn complete_fn_param() {
571571
// has mut kw
572572
check_edit(
573-
"mut bar",
573+
"mut ba",
574574
r#"
575575
fn f(foo: (), mut bar: u32) {}
576576
fn g(foo: (), mut ba$0)
@@ -583,7 +583,7 @@ fn g(foo: (), mut bar: u32)
583583

584584
// has type param
585585
check_edit(
586-
"mut bar",
586+
"mut ba: u32",
587587
r#"
588588
fn g(foo: (), mut ba$0: u32)
589589
fn f(foo: (), mut bar: u32) {}
@@ -599,7 +599,7 @@ fn f(foo: (), mut bar: u32) {}
599599
fn complete_fn_mut_param_add_comma() {
600600
// add leading and trailing comma
601601
check_edit(
602-
"mut bar",
602+
", mut ba",
603603
r#"
604604
fn f(foo: (), mut bar: u32) {}
605605
fn g(foo: ()mut ba$0 baz: ())
@@ -614,7 +614,7 @@ fn g(foo: (), mut bar: u32, baz: ())
614614
#[test]
615615
fn complete_fn_mut_param_has_attribute() {
616616
check_edit(
617-
"mut bar",
617+
"mut ba",
618618
r#"
619619
fn f(foo: (), #[baz = "qux"] mut bar: u32) {}
620620
fn g(foo: (), mut ba$0)
@@ -626,14 +626,26 @@ fn g(foo: (), #[baz = "qux"] mut bar: u32)
626626
);
627627

628628
check_edit(
629-
"mut bar",
629+
r#"#[baz = "qux"] mut ba"#,
630630
r#"
631631
fn f(foo: (), #[baz = "qux"] mut bar: u32) {}
632632
fn g(foo: (), #[baz = "qux"] mut ba$0)
633633
"#,
634634
r#"
635635
fn f(foo: (), #[baz = "qux"] mut bar: u32) {}
636636
fn g(foo: (), #[baz = "qux"] mut bar: u32)
637+
"#,
638+
);
639+
640+
check_edit(
641+
r#", #[baz = "qux"] mut ba"#,
642+
r#"
643+
fn f(foo: (), #[baz = "qux"] mut bar: u32) {}
644+
fn g(foo: ()#[baz = "qux"] mut ba$0)
645+
"#,
646+
r#"
647+
fn f(foo: (), #[baz = "qux"] mut bar: u32) {}
648+
fn g(foo: (), #[baz = "qux"] mut bar: u32)
637649
"#,
638650
);
639651
}

0 commit comments

Comments
 (0)