mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-03 12:13:43 +00:00
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:
parent
bed7be9ed9
commit
4cc3a6d4fe
@ -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);
|
||||
if impl_default_trait && !missing_fields.is_empty() {
|
||||
let completion_text = if ctx.token.to_string() == "." {
|
||||
".Default::default()"
|
||||
} else {
|
||||
"..Default::default()"
|
||||
};
|
||||
acc.add(
|
||||
CompletionItem::new(
|
||||
CompletionKind::Snippet,
|
||||
ctx.source_range(),
|
||||
"..Default::default()",
|
||||
)
|
||||
.insert_text("..Default::default()")
|
||||
.insert_text(completion_text)
|
||||
.kind(CompletionItemKind::Field)
|
||||
.build(),
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user