From 3d95c665561709f4017f28b2fb00a0bfb4661887 Mon Sep 17 00:00:00 2001 From: Nick Spain Date: Fri, 1 Jan 2021 11:17:15 +1100 Subject: Strip completion prefix of what has already been typed Per Veykril's suggestion, this removes the need to repeat the completion text twice. It also handles the completion in a more general case. --- crates/completion/src/completions/record.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'crates/completion') diff --git a/crates/completion/src/completions/record.rs b/crates/completion/src/completions/record.rs index f55ae11e6..e58b9a274 100644 --- a/crates/completion/src/completions/record.rs +++ b/crates/completion/src/completions/record.rs @@ -20,11 +20,10 @@ pub(crate) fn complete_record(acc: &mut Completions, ctx: &CompletionContext) -> let missing_fields = ctx.sema.record_literal_missing_fields(record_lit); if impl_default_trait && !missing_fields.is_empty() { - let completion_text = if ctx.token.to_string() == "." { - ".Default::default()" - } else { - "..Default::default()" - }; + let completion_text = "..Default::default()"; + let completion_text = completion_text + .strip_prefix(ctx.token.to_string().as_str()) + .unwrap_or(completion_text); acc.add( CompletionItem::new( CompletionKind::Snippet, -- cgit v1.2.3