aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Spain <[email protected]>2020-12-31 05:22:59 +0000
committerNick Spain <[email protected]>2020-12-31 05:23:05 +0000
commit4cc3a6d4fe16e342fcb2f791dd0ceccc188fb8ad (patch)
treeb14ad3f33cbef2370685eda791e3e6ef3e7386ce
parentbed7be9ed9f3eb905ae1c377f154fe0990b4c87f (diff)
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
-rw-r--r--crates/completion/src/completions/record.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/crates/completion/src/completions/record.rs b/crates/completion/src/completions/record.rs
index 91bf4a8ad..8f904adfd 100644
--- a/crates/completion/src/completions/record.rs
+++ b/crates/completion/src/completions/record.rs
@@ -20,13 +20,18 @@ pub(crate) fn complete_record(acc: &mut Completions, ctx: &CompletionContext) ->
20 20
21 let missing_fields = ctx.sema.record_literal_missing_fields(record_lit); 21 let missing_fields = ctx.sema.record_literal_missing_fields(record_lit);
22 if impl_default_trait && !missing_fields.is_empty() { 22 if impl_default_trait && !missing_fields.is_empty() {
23 let completion_text = if ctx.token.to_string() == "." {
24 ".Default::default()"
25 } else {
26 "..Default::default()"
27 };
23 acc.add( 28 acc.add(
24 CompletionItem::new( 29 CompletionItem::new(
25 CompletionKind::Snippet, 30 CompletionKind::Snippet,
26 ctx.source_range(), 31 ctx.source_range(),
27 "..Default::default()", 32 "..Default::default()",
28 ) 33 )
29 .insert_text("..Default::default()") 34 .insert_text(completion_text)
30 .kind(CompletionItemKind::Field) 35 .kind(CompletionItemKind::Field)
31 .build(), 36 .build(),
32 ); 37 );