diff options
author | yonip23 <[email protected]> | 2021-03-11 15:46:41 +0000 |
---|---|---|
committer | yonip23 <[email protected]> | 2021-03-11 15:46:41 +0000 |
commit | 99c4a41cd1a9f9ef0ee4f067f0069a23123b949a (patch) | |
tree | 37160de8384855fd5fadce3ca4a3de4dacdf98b8 /crates/ide_completion/src/completions/trait_impl.rs | |
parent | db6364fecc2b0e9a95d9aaece820a86265b4cb4f (diff) |
use references in CompletionItem's builder
Diffstat (limited to 'crates/ide_completion/src/completions/trait_impl.rs')
-rw-r--r-- | crates/ide_completion/src/completions/trait_impl.rs | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/crates/ide_completion/src/completions/trait_impl.rs b/crates/ide_completion/src/completions/trait_impl.rs index b999540b8..031f42d4a 100644 --- a/crates/ide_completion/src/completions/trait_impl.rs +++ b/crates/ide_completion/src/completions/trait_impl.rs | |||
@@ -145,9 +145,8 @@ fn add_function_impl( | |||
145 | format!("fn {}(..)", fn_name) | 145 | format!("fn {}(..)", fn_name) |
146 | }; | 146 | }; |
147 | 147 | ||
148 | let builder = CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label) | 148 | let mut builder = CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label); |
149 | .lookup_by(fn_name) | 149 | builder.lookup_by(fn_name).set_documentation(func.docs(ctx.db)); |
150 | .set_documentation(func.docs(ctx.db)); | ||
151 | 150 | ||
152 | let completion_kind = if func.self_param(ctx.db).is_some() { | 151 | let completion_kind = if func.self_param(ctx.db).is_some() { |
153 | CompletionItemKind::Method | 152 | CompletionItemKind::Method |
@@ -161,15 +160,15 @@ fn add_function_impl( | |||
161 | match ctx.config.snippet_cap { | 160 | match ctx.config.snippet_cap { |
162 | Some(cap) => { | 161 | Some(cap) => { |
163 | let snippet = format!("{} {{\n $0\n}}", function_decl); | 162 | let snippet = format!("{} {{\n $0\n}}", function_decl); |
164 | builder.snippet_edit(cap, TextEdit::replace(range, snippet)) | 163 | builder.snippet_edit(cap, TextEdit::replace(range, snippet)); |
165 | } | 164 | } |
166 | None => { | 165 | None => { |
167 | let header = format!("{} {{", function_decl); | 166 | let header = format!("{} {{", function_decl); |
168 | builder.text_edit(TextEdit::replace(range, header)) | 167 | builder.text_edit(TextEdit::replace(range, header)); |
169 | } | 168 | } |
170 | } | 169 | }; |
171 | .kind(completion_kind) | 170 | builder.kind(completion_kind); |
172 | .add_to(acc); | 171 | builder.add_to(acc); |
173 | } | 172 | } |
174 | } | 173 | } |
175 | 174 | ||
@@ -185,12 +184,14 @@ fn add_type_alias_impl( | |||
185 | 184 | ||
186 | let range = TextRange::new(type_def_node.text_range().start(), ctx.source_range().end()); | 185 | let range = TextRange::new(type_def_node.text_range().start(), ctx.source_range().end()); |
187 | 186 | ||
188 | CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone()) | 187 | let mut builder = |
188 | CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone()); | ||
189 | builder | ||
189 | .text_edit(TextEdit::replace(range, snippet)) | 190 | .text_edit(TextEdit::replace(range, snippet)) |
190 | .lookup_by(alias_name) | 191 | .lookup_by(alias_name) |
191 | .kind(SymbolKind::TypeAlias) | 192 | .kind(SymbolKind::TypeAlias) |
192 | .set_documentation(type_alias.docs(ctx.db)) | 193 | .set_documentation(type_alias.docs(ctx.db)); |
193 | .add_to(acc); | 194 | builder.add_to(acc); |
194 | } | 195 | } |
195 | 196 | ||
196 | fn add_const_impl( | 197 | fn add_const_impl( |
@@ -208,12 +209,14 @@ fn add_const_impl( | |||
208 | let range = | 209 | let range = |
209 | TextRange::new(const_def_node.text_range().start(), ctx.source_range().end()); | 210 | TextRange::new(const_def_node.text_range().start(), ctx.source_range().end()); |
210 | 211 | ||
211 | CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone()) | 212 | let mut builder = |
213 | CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone()); | ||
214 | builder | ||
212 | .text_edit(TextEdit::replace(range, snippet)) | 215 | .text_edit(TextEdit::replace(range, snippet)) |
213 | .lookup_by(const_name) | 216 | .lookup_by(const_name) |
214 | .kind(SymbolKind::Const) | 217 | .kind(SymbolKind::Const) |
215 | .set_documentation(const_.docs(ctx.db)) | 218 | .set_documentation(const_.docs(ctx.db)); |
216 | .add_to(acc); | 219 | builder.add_to(acc); |
217 | } | 220 | } |
218 | } | 221 | } |
219 | } | 222 | } |