aboutsummaryrefslogtreecommitdiff
path: root/crates/completion
diff options
context:
space:
mode:
authorNick Spain <[email protected]>2021-01-01 00:17:15 +0000
committerNick Spain <[email protected]>2021-01-01 00:17:15 +0000
commit3d95c665561709f4017f28b2fb00a0bfb4661887 (patch)
tree5fea5dbd1150f99c2d0bf07258131fc4e5600eec /crates/completion
parent49eeeb61ae309a245de2f9bf65ffb0ea9576ba6c (diff)
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.
Diffstat (limited to 'crates/completion')
-rw-r--r--crates/completion/src/completions/record.rs9
1 files changed, 4 insertions, 5 deletions
diff --git a/crates/completion/src/completions/record.rs b/crates/completion/src/completions/record.rs
index f55ae11e6..e58b9a274 100644
--- a/crates/completion/src/completions/record.rs
+++ b/crates/completion/src/completions/record.rs
@@ -20,11 +20,10 @@ 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() == "." { 23 let completion_text = "..Default::default()";
24 ".Default::default()" 24 let completion_text = completion_text
25 } else { 25 .strip_prefix(ctx.token.to_string().as_str())
26 "..Default::default()" 26 .unwrap_or(completion_text);
27 };
28 acc.add( 27 acc.add(
29 CompletionItem::new( 28 CompletionItem::new(
30 CompletionKind::Snippet, 29 CompletionKind::Snippet,