]> git.lizzy.rs Git - rust.git/blobdiff - crates/ide_completion/src/completions/trait_impl.rs
use references in CompletionItem's builder
[rust.git] / crates / ide_completion / src / completions / trait_impl.rs
index b999540b84d6563b62fceec54449e0caeb07b858..031f42d4a4c88a6182772414a3236a43595337b5 100644 (file)
@@ -145,9 +145,8 @@ fn add_function_impl(
         format!("fn {}(..)", fn_name)
     };
 
-    let builder = CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label)
-        .lookup_by(fn_name)
-        .set_documentation(func.docs(ctx.db));
+    let mut builder = CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label);
+    builder.lookup_by(fn_name).set_documentation(func.docs(ctx.db));
 
     let completion_kind = if func.self_param(ctx.db).is_some() {
         CompletionItemKind::Method
@@ -161,15 +160,15 @@ fn add_function_impl(
         match ctx.config.snippet_cap {
             Some(cap) => {
                 let snippet = format!("{} {{\n    $0\n}}", function_decl);
-                builder.snippet_edit(cap, TextEdit::replace(range, snippet))
+                builder.snippet_edit(cap, TextEdit::replace(range, snippet));
             }
             None => {
                 let header = format!("{} {{", function_decl);
-                builder.text_edit(TextEdit::replace(range, header))
+                builder.text_edit(TextEdit::replace(range, header));
             }
-        }
-        .kind(completion_kind)
-        .add_to(acc);
+        };
+        builder.kind(completion_kind);
+        builder.add_to(acc);
     }
 }
 
@@ -185,12 +184,14 @@ fn add_type_alias_impl(
 
     let range = TextRange::new(type_def_node.text_range().start(), ctx.source_range().end());
 
-    CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone())
+    let mut builder =
+        CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone());
+    builder
         .text_edit(TextEdit::replace(range, snippet))
         .lookup_by(alias_name)
         .kind(SymbolKind::TypeAlias)
-        .set_documentation(type_alias.docs(ctx.db))
-        .add_to(acc);
+        .set_documentation(type_alias.docs(ctx.db));
+    builder.add_to(acc);
 }
 
 fn add_const_impl(
@@ -208,12 +209,14 @@ fn add_const_impl(
             let range =
                 TextRange::new(const_def_node.text_range().start(), ctx.source_range().end());
 
-            CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone())
+            let mut builder =
+                CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone());
+            builder
                 .text_edit(TextEdit::replace(range, snippet))
                 .lookup_by(const_name)
                 .kind(SymbolKind::Const)
-                .set_documentation(const_.docs(ctx.db))
-                .add_to(acc);
+                .set_documentation(const_.docs(ctx.db));
+            builder.add_to(acc);
         }
     }
 }