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.
This commit is contained in:
Nick Spain 2021-01-01 11:17:15 +11:00
parent 49eeeb61ae
commit 3d95c66556

View File

@ -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,