Fix completion of Default struct update syntax

Previously the inserted text was always `..Default::default()` which ends up as `...Default::default()`
if `.` was typed. Now  checks if the current token is `.` and inserts `.Default::default()`
if it is, so `..Default::default()` is correctly completed.

Fixes #6969
This commit is contained in:
Nick Spain 2020-12-31 16:22:59 +11:00
parent bed7be9ed9
commit 4cc3a6d4fe

View File

@ -20,13 +20,18 @@ pub(crate) fn complete_record(acc: &mut Completions, ctx: &CompletionContext) ->
let missing_fields = ctx.sema.record_literal_missing_fields(record_lit); let missing_fields = ctx.sema.record_literal_missing_fields(record_lit);
if impl_default_trait && !missing_fields.is_empty() { if impl_default_trait && !missing_fields.is_empty() {
let completion_text = if ctx.token.to_string() == "." {
".Default::default()"
} else {
"..Default::default()"
};
acc.add( acc.add(
CompletionItem::new( CompletionItem::new(
CompletionKind::Snippet, CompletionKind::Snippet,
ctx.source_range(), ctx.source_range(),
"..Default::default()", "..Default::default()",
) )
.insert_text("..Default::default()") .insert_text(completion_text)
.kind(CompletionItemKind::Field) .kind(CompletionItemKind::Field)
.build(), .build(),
); );