]> git.lizzy.rs Git - rust.git/commitdiff
Strip completion prefix of what has already been typed
authorNick Spain <nicholas.spain@stileeducation.com>
Fri, 1 Jan 2021 00:17:15 +0000 (11:17 +1100)
committerNick Spain <nicholas.spain@stileeducation.com>
Fri, 1 Jan 2021 00:17:15 +0000 (11:17 +1100)
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

index f55ae11e6b38e232b5bf66a05be39b2b1ee08bd4..e58b9a27448b0e71c4a403800f594d7396ba7aff 100644 (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,