diff options
Diffstat (limited to 'crates/ide_completion')
-rw-r--r-- | crates/ide_completion/src/completions/attribute.rs | 18 | ||||
-rw-r--r-- | crates/ide_completion/src/completions/fn_param.rs | 6 | ||||
-rw-r--r-- | crates/ide_completion/src/completions/keyword.rs | 36 | ||||
-rw-r--r-- | crates/ide_completion/src/completions/mod_.rs | 7 | ||||
-rw-r--r-- | crates/ide_completion/src/completions/postfix.rs | 8 | ||||
-rw-r--r-- | crates/ide_completion/src/completions/record.rs | 6 | ||||
-rw-r--r-- | crates/ide_completion/src/completions/snippet.rs | 22 | ||||
-rw-r--r-- | crates/ide_completion/src/completions/trait_impl.rs | 27 | ||||
-rw-r--r-- | crates/ide_completion/src/render.rs | 15 | ||||
-rw-r--r-- | crates/ide_completion/src/render/enum_variant.rs | 11 | ||||
-rw-r--r-- | crates/ide_completion/src/render/function.rs | 7 | ||||
-rw-r--r-- | crates/ide_completion/src/render/macro_.rs | 13 | ||||
-rw-r--r-- | crates/ide_completion/src/render/pattern.rs | 17 |
13 files changed, 90 insertions, 103 deletions
diff --git a/crates/ide_completion/src/completions/attribute.rs b/crates/ide_completion/src/completions/attribute.rs index 14376b924..e846678b4 100644 --- a/crates/ide_completion/src/completions/attribute.rs +++ b/crates/ide_completion/src/completions/attribute.rs | |||
@@ -168,20 +168,20 @@ fn complete_derive(acc: &mut Completions, ctx: &CompletionContext, derive_input: | |||
168 | ); | 168 | ); |
169 | let lookup = components.join(", "); | 169 | let lookup = components.join(", "); |
170 | let label = components.iter().rev().join(", "); | 170 | let label = components.iter().rev().join(", "); |
171 | let mut builder = | 171 | let mut item = |
172 | CompletionItem::new(CompletionKind::Attribute, ctx.source_range(), label); | 172 | CompletionItem::new(CompletionKind::Attribute, ctx.source_range(), label); |
173 | builder.lookup_by(lookup).kind(CompletionItemKind::Attribute); | 173 | item.lookup_by(lookup).kind(CompletionItemKind::Attribute); |
174 | builder.add_to(acc); | 174 | item.add_to(acc); |
175 | } | 175 | } |
176 | 176 | ||
177 | for custom_derive_name in get_derive_names_in_scope(ctx).difference(&existing_derives) { | 177 | for custom_derive_name in get_derive_names_in_scope(ctx).difference(&existing_derives) { |
178 | let mut builder = CompletionItem::new( | 178 | let mut item = CompletionItem::new( |
179 | CompletionKind::Attribute, | 179 | CompletionKind::Attribute, |
180 | ctx.source_range(), | 180 | ctx.source_range(), |
181 | custom_derive_name, | 181 | custom_derive_name, |
182 | ); | 182 | ); |
183 | builder.kind(CompletionItemKind::Attribute); | 183 | item.kind(CompletionItemKind::Attribute); |
184 | builder.add_to(acc); | 184 | item.add_to(acc); |
185 | } | 185 | } |
186 | } | 186 | } |
187 | } | 187 | } |
@@ -197,13 +197,13 @@ fn complete_lint( | |||
197 | .into_iter() | 197 | .into_iter() |
198 | .filter(|completion| !existing_lints.contains(completion.label)) | 198 | .filter(|completion| !existing_lints.contains(completion.label)) |
199 | { | 199 | { |
200 | let mut builder = CompletionItem::new( | 200 | let mut item = CompletionItem::new( |
201 | CompletionKind::Attribute, | 201 | CompletionKind::Attribute, |
202 | ctx.source_range(), | 202 | ctx.source_range(), |
203 | lint_completion.label, | 203 | lint_completion.label, |
204 | ); | 204 | ); |
205 | builder.kind(CompletionItemKind::Attribute).detail(lint_completion.description); | 205 | item.kind(CompletionItemKind::Attribute).detail(lint_completion.description); |
206 | builder.add_to(acc) | 206 | item.add_to(acc) |
207 | } | 207 | } |
208 | } | 208 | } |
209 | } | 209 | } |
diff --git a/crates/ide_completion/src/completions/fn_param.rs b/crates/ide_completion/src/completions/fn_param.rs index 9600a049a..0243dce56 100644 --- a/crates/ide_completion/src/completions/fn_param.rs +++ b/crates/ide_completion/src/completions/fn_param.rs | |||
@@ -54,9 +54,9 @@ pub(crate) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext) | |||
54 | } | 54 | } |
55 | 55 | ||
56 | params.into_iter().for_each(|(label, lookup)| { | 56 | params.into_iter().for_each(|(label, lookup)| { |
57 | let mut builder = CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label); | 57 | let mut item = CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label); |
58 | builder.kind(CompletionItemKind::Binding).lookup_by(lookup); | 58 | item.kind(CompletionItemKind::Binding).lookup_by(lookup); |
59 | builder.add_to(acc) | 59 | item.add_to(acc) |
60 | }); | 60 | }); |
61 | } | 61 | } |
62 | 62 | ||
diff --git a/crates/ide_completion/src/completions/keyword.rs b/crates/ide_completion/src/completions/keyword.rs index aa3be712d..b635e0ca3 100644 --- a/crates/ide_completion/src/completions/keyword.rs +++ b/crates/ide_completion/src/completions/keyword.rs | |||
@@ -12,21 +12,19 @@ pub(crate) fn complete_use_tree_keyword(acc: &mut Completions, ctx: &CompletionC | |||
12 | 12 | ||
13 | if ctx.use_item_syntax.is_some() { | 13 | if ctx.use_item_syntax.is_some() { |
14 | if ctx.path_qual.is_none() { | 14 | if ctx.path_qual.is_none() { |
15 | let mut crate_builder = | 15 | let mut item = CompletionItem::new(CompletionKind::Keyword, source_range, "crate::"); |
16 | CompletionItem::new(CompletionKind::Keyword, source_range, "crate::"); | 16 | item.kind(CompletionItemKind::Keyword).insert_text("crate::"); |
17 | crate_builder.kind(CompletionItemKind::Keyword).insert_text("crate::"); | 17 | item.add_to(acc); |
18 | crate_builder.add_to(acc); | ||
19 | } | 18 | } |
20 | let mut self_builder = CompletionItem::new(CompletionKind::Keyword, source_range, "self"); | 19 | let mut item = CompletionItem::new(CompletionKind::Keyword, source_range, "self"); |
21 | self_builder.kind(CompletionItemKind::Keyword); | 20 | item.kind(CompletionItemKind::Keyword); |
22 | self_builder.add_to(acc); | 21 | item.add_to(acc); |
23 | if iter::successors(ctx.path_qual.clone(), |p| p.qualifier()) | 22 | if iter::successors(ctx.path_qual.clone(), |p| p.qualifier()) |
24 | .all(|p| p.segment().and_then(|s| s.super_token()).is_some()) | 23 | .all(|p| p.segment().and_then(|s| s.super_token()).is_some()) |
25 | { | 24 | { |
26 | let mut super_builder = | 25 | let mut item = CompletionItem::new(CompletionKind::Keyword, source_range, "super::"); |
27 | CompletionItem::new(CompletionKind::Keyword, source_range, "super::"); | 26 | item.kind(CompletionItemKind::Keyword).insert_text("super::"); |
28 | super_builder.kind(CompletionItemKind::Keyword).insert_text("super::"); | 27 | item.add_to(acc); |
29 | super_builder.add_to(acc); | ||
30 | } | 28 | } |
31 | } | 29 | } |
32 | 30 | ||
@@ -34,10 +32,10 @@ pub(crate) fn complete_use_tree_keyword(acc: &mut Completions, ctx: &CompletionC | |||
34 | if let Some(receiver) = &ctx.dot_receiver { | 32 | if let Some(receiver) = &ctx.dot_receiver { |
35 | if let Some(ty) = ctx.sema.type_of_expr(receiver) { | 33 | if let Some(ty) = ctx.sema.type_of_expr(receiver) { |
36 | if ty.impls_future(ctx.db) { | 34 | if ty.impls_future(ctx.db) { |
37 | let mut builder = | 35 | let mut item = |
38 | CompletionItem::new(CompletionKind::Keyword, ctx.source_range(), "await"); | 36 | CompletionItem::new(CompletionKind::Keyword, ctx.source_range(), "await"); |
39 | builder.kind(CompletionItemKind::Keyword).detail("expr.await").insert_text("await"); | 37 | item.kind(CompletionItemKind::Keyword).detail("expr.await").insert_text("await"); |
40 | builder.add_to(acc); | 38 | item.add_to(acc); |
41 | } | 39 | } |
42 | }; | 40 | }; |
43 | } | 41 | } |
@@ -164,8 +162,8 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte | |||
164 | } | 162 | } |
165 | 163 | ||
166 | fn add_keyword(ctx: &CompletionContext, acc: &mut Completions, kw: &str, snippet: &str) { | 164 | fn add_keyword(ctx: &CompletionContext, acc: &mut Completions, kw: &str, snippet: &str) { |
167 | let mut builder = CompletionItem::new(CompletionKind::Keyword, ctx.source_range(), kw); | 165 | let mut item = CompletionItem::new(CompletionKind::Keyword, ctx.source_range(), kw); |
168 | builder.kind(CompletionItemKind::Keyword); | 166 | item.kind(CompletionItemKind::Keyword); |
169 | 167 | ||
170 | match ctx.config.snippet_cap { | 168 | match ctx.config.snippet_cap { |
171 | Some(cap) => { | 169 | Some(cap) => { |
@@ -177,13 +175,13 @@ fn add_keyword(ctx: &CompletionContext, acc: &mut Completions, kw: &str, snippet | |||
177 | } else { | 175 | } else { |
178 | snippet | 176 | snippet |
179 | }; | 177 | }; |
180 | builder.insert_snippet(cap, snippet); | 178 | item.insert_snippet(cap, snippet); |
181 | } | 179 | } |
182 | None => { | 180 | None => { |
183 | builder.insert_text(if snippet.contains('$') { kw } else { snippet }); | 181 | item.insert_text(if snippet.contains('$') { kw } else { snippet }); |
184 | } | 182 | } |
185 | }; | 183 | }; |
186 | acc.add(builder.build()); | 184 | item.add_to(acc); |
187 | } | 185 | } |
188 | 186 | ||
189 | #[cfg(test)] | 187 | #[cfg(test)] |
diff --git a/crates/ide_completion/src/completions/mod_.rs b/crates/ide_completion/src/completions/mod_.rs index fc4ac7a0d..4f9415736 100644 --- a/crates/ide_completion/src/completions/mod_.rs +++ b/crates/ide_completion/src/completions/mod_.rs | |||
@@ -80,10 +80,9 @@ pub(crate) fn complete_mod(acc: &mut Completions, ctx: &CompletionContext) -> Op | |||
80 | if mod_under_caret.semicolon_token().is_none() { | 80 | if mod_under_caret.semicolon_token().is_none() { |
81 | label.push(';'); | 81 | label.push(';'); |
82 | } | 82 | } |
83 | let mut builder = | 83 | let mut item = CompletionItem::new(CompletionKind::Magic, ctx.source_range(), &label); |
84 | CompletionItem::new(CompletionKind::Magic, ctx.source_range(), &label); | 84 | item.kind(SymbolKind::Module); |
85 | builder.kind(SymbolKind::Module); | 85 | item.add_to(acc) |
86 | builder.add_to(acc) | ||
87 | }); | 86 | }); |
88 | 87 | ||
89 | Some(()) | 88 | Some(()) |
diff --git a/crates/ide_completion/src/completions/postfix.rs b/crates/ide_completion/src/completions/postfix.rs index 8551e0168..ac69b720a 100644 --- a/crates/ide_completion/src/completions/postfix.rs +++ b/crates/ide_completion/src/completions/postfix.rs | |||
@@ -297,11 +297,9 @@ fn postfix_snippet( | |||
297 | let delete_range = TextRange::new(receiver_range.start(), ctx.source_range().end()); | 297 | let delete_range = TextRange::new(receiver_range.start(), ctx.source_range().end()); |
298 | TextEdit::replace(delete_range, snippet.to_string()) | 298 | TextEdit::replace(delete_range, snippet.to_string()) |
299 | }; | 299 | }; |
300 | CompletionItem::new(CompletionKind::Postfix, ctx.source_range(), label) | 300 | let mut item = CompletionItem::new(CompletionKind::Postfix, ctx.source_range(), label); |
301 | .detail(detail) | 301 | item.detail(detail).kind(CompletionItemKind::Snippet).snippet_edit(cap, edit); |
302 | .kind(CompletionItemKind::Snippet) | 302 | item |
303 | .snippet_edit(cap, edit) | ||
304 | .clone() | ||
305 | } | 303 | } |
306 | 304 | ||
307 | #[cfg(test)] | 305 | #[cfg(test)] |
diff --git a/crates/ide_completion/src/completions/record.rs b/crates/ide_completion/src/completions/record.rs index b9af09698..2f95b8687 100644 --- a/crates/ide_completion/src/completions/record.rs +++ b/crates/ide_completion/src/completions/record.rs | |||
@@ -22,13 +22,13 @@ pub(crate) fn complete_record(acc: &mut Completions, ctx: &CompletionContext) -> | |||
22 | let completion_text = completion_text | 22 | let completion_text = completion_text |
23 | .strip_prefix(ctx.token.to_string().as_str()) | 23 | .strip_prefix(ctx.token.to_string().as_str()) |
24 | .unwrap_or(completion_text); | 24 | .unwrap_or(completion_text); |
25 | let mut builder = CompletionItem::new( | 25 | let mut item = CompletionItem::new( |
26 | CompletionKind::Snippet, | 26 | CompletionKind::Snippet, |
27 | ctx.source_range(), | 27 | ctx.source_range(), |
28 | "..Default::default()", | 28 | "..Default::default()", |
29 | ); | 29 | ); |
30 | builder.insert_text(completion_text).kind(SymbolKind::Field); | 30 | item.insert_text(completion_text).kind(SymbolKind::Field); |
31 | acc.add(builder.build()); | 31 | item.add_to(acc); |
32 | } | 32 | } |
33 | 33 | ||
34 | missing_fields | 34 | missing_fields |
diff --git a/crates/ide_completion/src/completions/snippet.rs b/crates/ide_completion/src/completions/snippet.rs index a4d18cecd..7f7830976 100644 --- a/crates/ide_completion/src/completions/snippet.rs +++ b/crates/ide_completion/src/completions/snippet.rs | |||
@@ -8,8 +8,9 @@ use crate::{ | |||
8 | }; | 8 | }; |
9 | 9 | ||
10 | fn snippet(ctx: &CompletionContext, cap: SnippetCap, label: &str, snippet: &str) -> Builder { | 10 | fn snippet(ctx: &CompletionContext, cap: SnippetCap, label: &str, snippet: &str) -> Builder { |
11 | let mut builder = CompletionItem::new(CompletionKind::Snippet, ctx.source_range(), label); | 11 | let mut item = CompletionItem::new(CompletionKind::Snippet, ctx.source_range(), label); |
12 | builder.insert_snippet(cap, snippet).kind(CompletionItemKind::Snippet).clone() | 12 | item.insert_snippet(cap, snippet).kind(CompletionItemKind::Snippet); |
13 | item | ||
13 | } | 14 | } |
14 | 15 | ||
15 | pub(crate) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionContext) { | 16 | pub(crate) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionContext) { |
@@ -34,7 +35,7 @@ pub(crate) fn complete_item_snippet(acc: &mut Completions, ctx: &CompletionConte | |||
34 | None => return, | 35 | None => return, |
35 | }; | 36 | }; |
36 | 37 | ||
37 | let mut test_module_builder = snippet( | 38 | let mut item = snippet( |
38 | ctx, | 39 | ctx, |
39 | cap, | 40 | cap, |
40 | "tmod (Test module)", | 41 | "tmod (Test module)", |
@@ -49,10 +50,10 @@ mod tests { | |||
49 | } | 50 | } |
50 | }", | 51 | }", |
51 | ); | 52 | ); |
52 | test_module_builder.lookup_by("tmod"); | 53 | item.lookup_by("tmod"); |
53 | test_module_builder.add_to(acc); | 54 | item.add_to(acc); |
54 | 55 | ||
55 | let mut test_function_builder = snippet( | 56 | let mut item = snippet( |
56 | ctx, | 57 | ctx, |
57 | cap, | 58 | cap, |
58 | "tfn (Test function)", | 59 | "tfn (Test function)", |
@@ -62,12 +63,11 @@ fn ${1:feature}() { | |||
62 | $0 | 63 | $0 |
63 | }", | 64 | }", |
64 | ); | 65 | ); |
65 | test_function_builder.lookup_by("tfn"); | 66 | item.lookup_by("tfn"); |
66 | test_function_builder.add_to(acc); | 67 | item.add_to(acc); |
67 | 68 | ||
68 | let macro_rules_builder = | 69 | let item = snippet(ctx, cap, "macro_rules", "macro_rules! $1 {\n\t($2) => {\n\t\t$0\n\t};\n}"); |
69 | snippet(ctx, cap, "macro_rules", "macro_rules! $1 {\n\t($2) => {\n\t\t$0\n\t};\n}"); | 70 | item.add_to(acc); |
70 | macro_rules_builder.add_to(acc); | ||
71 | } | 71 | } |
72 | 72 | ||
73 | #[cfg(test)] | 73 | #[cfg(test)] |
diff --git a/crates/ide_completion/src/completions/trait_impl.rs b/crates/ide_completion/src/completions/trait_impl.rs index 031f42d4a..5a7361f8e 100644 --- a/crates/ide_completion/src/completions/trait_impl.rs +++ b/crates/ide_completion/src/completions/trait_impl.rs | |||
@@ -145,8 +145,8 @@ fn add_function_impl( | |||
145 | format!("fn {}(..)", fn_name) | 145 | format!("fn {}(..)", fn_name) |
146 | }; | 146 | }; |
147 | 147 | ||
148 | let mut builder = CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label); | 148 | let mut item = CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label); |
149 | builder.lookup_by(fn_name).set_documentation(func.docs(ctx.db)); | 149 | item.lookup_by(fn_name).set_documentation(func.docs(ctx.db)); |
150 | 150 | ||
151 | let completion_kind = if func.self_param(ctx.db).is_some() { | 151 | let completion_kind = if func.self_param(ctx.db).is_some() { |
152 | CompletionItemKind::Method | 152 | CompletionItemKind::Method |
@@ -160,15 +160,15 @@ fn add_function_impl( | |||
160 | match ctx.config.snippet_cap { | 160 | match ctx.config.snippet_cap { |
161 | Some(cap) => { | 161 | Some(cap) => { |
162 | let snippet = format!("{} {{\n $0\n}}", function_decl); | 162 | let snippet = format!("{} {{\n $0\n}}", function_decl); |
163 | builder.snippet_edit(cap, TextEdit::replace(range, snippet)); | 163 | item.snippet_edit(cap, TextEdit::replace(range, snippet)); |
164 | } | 164 | } |
165 | None => { | 165 | None => { |
166 | let header = format!("{} {{", function_decl); | 166 | let header = format!("{} {{", function_decl); |
167 | builder.text_edit(TextEdit::replace(range, header)); | 167 | item.text_edit(TextEdit::replace(range, header)); |
168 | } | 168 | } |
169 | }; | 169 | }; |
170 | builder.kind(completion_kind); | 170 | item.kind(completion_kind); |
171 | builder.add_to(acc); | 171 | item.add_to(acc); |
172 | } | 172 | } |
173 | } | 173 | } |
174 | 174 | ||
@@ -184,14 +184,12 @@ fn add_type_alias_impl( | |||
184 | 184 | ||
185 | 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()); |
186 | 186 | ||
187 | let mut builder = | 187 | let mut item = CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone()); |
188 | CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone()); | 188 | item.text_edit(TextEdit::replace(range, snippet)) |
189 | builder | ||
190 | .text_edit(TextEdit::replace(range, snippet)) | ||
191 | .lookup_by(alias_name) | 189 | .lookup_by(alias_name) |
192 | .kind(SymbolKind::TypeAlias) | 190 | .kind(SymbolKind::TypeAlias) |
193 | .set_documentation(type_alias.docs(ctx.db)); | 191 | .set_documentation(type_alias.docs(ctx.db)); |
194 | builder.add_to(acc); | 192 | item.add_to(acc); |
195 | } | 193 | } |
196 | 194 | ||
197 | fn add_const_impl( | 195 | fn add_const_impl( |
@@ -209,14 +207,13 @@ fn add_const_impl( | |||
209 | let range = | 207 | let range = |
210 | TextRange::new(const_def_node.text_range().start(), ctx.source_range().end()); | 208 | TextRange::new(const_def_node.text_range().start(), ctx.source_range().end()); |
211 | 209 | ||
212 | let mut builder = | 210 | let mut item = |
213 | CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone()); | 211 | CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone()); |
214 | builder | 212 | item.text_edit(TextEdit::replace(range, snippet)) |
215 | .text_edit(TextEdit::replace(range, snippet)) | ||
216 | .lookup_by(const_name) | 213 | .lookup_by(const_name) |
217 | .kind(SymbolKind::Const) | 214 | .kind(SymbolKind::Const) |
218 | .set_documentation(const_.docs(ctx.db)); | 215 | .set_documentation(const_.docs(ctx.db)); |
219 | builder.add_to(acc); | 216 | item.add_to(acc); |
220 | } | 217 | } |
221 | } | 218 | } |
222 | } | 219 | } |
diff --git a/crates/ide_completion/src/render.rs b/crates/ide_completion/src/render.rs index c50cba0e0..f7f9084d9 100644 --- a/crates/ide_completion/src/render.rs +++ b/crates/ide_completion/src/render.rs | |||
@@ -145,34 +145,33 @@ impl<'a> Render<'a> { | |||
145 | fn add_field(&mut self, field: hir::Field, ty: &Type) -> CompletionItem { | 145 | fn add_field(&mut self, field: hir::Field, ty: &Type) -> CompletionItem { |
146 | let is_deprecated = self.ctx.is_deprecated(field); | 146 | let is_deprecated = self.ctx.is_deprecated(field); |
147 | let name = field.name(self.ctx.db()); | 147 | let name = field.name(self.ctx.db()); |
148 | let mut builder = CompletionItem::new( | 148 | let mut item = CompletionItem::new( |
149 | CompletionKind::Reference, | 149 | CompletionKind::Reference, |
150 | self.ctx.source_range(), | 150 | self.ctx.source_range(), |
151 | name.to_string(), | 151 | name.to_string(), |
152 | ); | 152 | ); |
153 | builder | 153 | item.kind(SymbolKind::Field) |
154 | .kind(SymbolKind::Field) | ||
155 | .detail(ty.display(self.ctx.db()).to_string()) | 154 | .detail(ty.display(self.ctx.db()).to_string()) |
156 | .set_documentation(field.docs(self.ctx.db())) | 155 | .set_documentation(field.docs(self.ctx.db())) |
157 | .set_deprecated(is_deprecated); | 156 | .set_deprecated(is_deprecated); |
158 | 157 | ||
159 | if let Some(relevance) = compute_relevance(&self.ctx, &ty, &name.to_string()) { | 158 | if let Some(relevance) = compute_relevance(&self.ctx, &ty, &name.to_string()) { |
160 | builder.set_relevance(relevance); | 159 | item.set_relevance(relevance); |
161 | } | 160 | } |
162 | 161 | ||
163 | builder.build() | 162 | item.build() |
164 | } | 163 | } |
165 | 164 | ||
166 | fn add_tuple_field(&mut self, field: usize, ty: &Type) -> CompletionItem { | 165 | fn add_tuple_field(&mut self, field: usize, ty: &Type) -> CompletionItem { |
167 | let mut builder = CompletionItem::new( | 166 | let mut item = CompletionItem::new( |
168 | CompletionKind::Reference, | 167 | CompletionKind::Reference, |
169 | self.ctx.source_range(), | 168 | self.ctx.source_range(), |
170 | field.to_string(), | 169 | field.to_string(), |
171 | ); | 170 | ); |
172 | 171 | ||
173 | builder.kind(SymbolKind::Field).detail(ty.display(self.ctx.db()).to_string()); | 172 | item.kind(SymbolKind::Field).detail(ty.display(self.ctx.db()).to_string()); |
174 | 173 | ||
175 | builder.build() | 174 | item.build() |
176 | } | 175 | } |
177 | 176 | ||
178 | fn render_resolution( | 177 | fn render_resolution( |
diff --git a/crates/ide_completion/src/render/enum_variant.rs b/crates/ide_completion/src/render/enum_variant.rs index 23c43496e..e8cfcc0c7 100644 --- a/crates/ide_completion/src/render/enum_variant.rs +++ b/crates/ide_completion/src/render/enum_variant.rs | |||
@@ -55,13 +55,12 @@ impl<'a> EnumRender<'a> { | |||
55 | } | 55 | } |
56 | 56 | ||
57 | fn render(self, import_to_add: Option<ImportEdit>) -> CompletionItem { | 57 | fn render(self, import_to_add: Option<ImportEdit>) -> CompletionItem { |
58 | let mut builder = CompletionItem::new( | 58 | let mut item = CompletionItem::new( |
59 | CompletionKind::Reference, | 59 | CompletionKind::Reference, |
60 | self.ctx.source_range(), | 60 | self.ctx.source_range(), |
61 | self.qualified_name.clone(), | 61 | self.qualified_name.clone(), |
62 | ); | 62 | ); |
63 | builder | 63 | item.kind(SymbolKind::Variant) |
64 | .kind(SymbolKind::Variant) | ||
65 | .set_documentation(self.variant.docs(self.ctx.db())) | 64 | .set_documentation(self.variant.docs(self.ctx.db())) |
66 | .set_deprecated(self.ctx.is_deprecated(self.variant)) | 65 | .set_deprecated(self.ctx.is_deprecated(self.variant)) |
67 | .add_import(import_to_add) | 66 | .add_import(import_to_add) |
@@ -70,12 +69,12 @@ impl<'a> EnumRender<'a> { | |||
70 | if self.variant_kind == StructKind::Tuple { | 69 | if self.variant_kind == StructKind::Tuple { |
71 | cov_mark::hit!(inserts_parens_for_tuple_enums); | 70 | cov_mark::hit!(inserts_parens_for_tuple_enums); |
72 | let params = Params::Anonymous(self.variant.fields(self.ctx.db()).len()); | 71 | let params = Params::Anonymous(self.variant.fields(self.ctx.db()).len()); |
73 | builder.add_call_parens(self.ctx.completion, self.short_qualified_name, params); | 72 | item.add_call_parens(self.ctx.completion, self.short_qualified_name, params); |
74 | } else if self.path.is_some() { | 73 | } else if self.path.is_some() { |
75 | builder.lookup_by(self.short_qualified_name); | 74 | item.lookup_by(self.short_qualified_name); |
76 | } | 75 | } |
77 | 76 | ||
78 | builder.build() | 77 | item.build() |
79 | } | 78 | } |
80 | 79 | ||
81 | fn detail(&self) -> String { | 80 | fn detail(&self) -> String { |
diff --git a/crates/ide_completion/src/render/function.rs b/crates/ide_completion/src/render/function.rs index 1e2f45f14..f4dabe3d1 100644 --- a/crates/ide_completion/src/render/function.rs +++ b/crates/ide_completion/src/render/function.rs | |||
@@ -41,13 +41,12 @@ impl<'a> FunctionRender<'a> { | |||
41 | 41 | ||
42 | fn render(self, import_to_add: Option<ImportEdit>) -> CompletionItem { | 42 | fn render(self, import_to_add: Option<ImportEdit>) -> CompletionItem { |
43 | let params = self.params(); | 43 | let params = self.params(); |
44 | let mut builder = CompletionItem::new( | 44 | let mut item = CompletionItem::new( |
45 | CompletionKind::Reference, | 45 | CompletionKind::Reference, |
46 | self.ctx.source_range(), | 46 | self.ctx.source_range(), |
47 | self.name.clone(), | 47 | self.name.clone(), |
48 | ); | 48 | ); |
49 | builder | 49 | item.kind(self.kind()) |
50 | .kind(self.kind()) | ||
51 | .set_documentation(self.ctx.docs(self.func)) | 50 | .set_documentation(self.ctx.docs(self.func)) |
52 | .set_deprecated( | 51 | .set_deprecated( |
53 | self.ctx.is_deprecated(self.func) || self.ctx.is_deprecated_assoc_item(self.func), | 52 | self.ctx.is_deprecated(self.func) || self.ctx.is_deprecated_assoc_item(self.func), |
@@ -56,7 +55,7 @@ impl<'a> FunctionRender<'a> { | |||
56 | .add_call_parens(self.ctx.completion, self.name, params) | 55 | .add_call_parens(self.ctx.completion, self.name, params) |
57 | .add_import(import_to_add); | 56 | .add_import(import_to_add); |
58 | 57 | ||
59 | builder.build() | 58 | item.build() |
60 | } | 59 | } |
61 | 60 | ||
62 | fn detail(&self) -> String { | 61 | fn detail(&self) -> String { |
diff --git a/crates/ide_completion/src/render/macro_.rs b/crates/ide_completion/src/render/macro_.rs index 727f5e02e..3fa21ba7c 100644 --- a/crates/ide_completion/src/render/macro_.rs +++ b/crates/ide_completion/src/render/macro_.rs | |||
@@ -39,10 +39,9 @@ impl<'a> MacroRender<'a> { | |||
39 | } | 39 | } |
40 | 40 | ||
41 | fn render(&self, import_to_add: Option<ImportEdit>) -> Option<CompletionItem> { | 41 | fn render(&self, import_to_add: Option<ImportEdit>) -> Option<CompletionItem> { |
42 | let mut builder = | 42 | let mut item = |
43 | CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), &self.label()); | 43 | CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), &self.label()); |
44 | builder | 44 | item.kind(SymbolKind::Macro) |
45 | .kind(SymbolKind::Macro) | ||
46 | .set_documentation(self.docs.clone()) | 45 | .set_documentation(self.docs.clone()) |
47 | .set_deprecated(self.ctx.is_deprecated(self.macro_)) | 46 | .set_deprecated(self.ctx.is_deprecated(self.macro_)) |
48 | .add_import(import_to_add) | 47 | .add_import(import_to_add) |
@@ -53,18 +52,18 @@ impl<'a> MacroRender<'a> { | |||
53 | Some(cap) if needs_bang => { | 52 | Some(cap) if needs_bang => { |
54 | let snippet = self.snippet(); | 53 | let snippet = self.snippet(); |
55 | let lookup = self.lookup(); | 54 | let lookup = self.lookup(); |
56 | builder.insert_snippet(cap, snippet).lookup_by(lookup); | 55 | item.insert_snippet(cap, snippet).lookup_by(lookup); |
57 | } | 56 | } |
58 | None if needs_bang => { | 57 | None if needs_bang => { |
59 | builder.insert_text(self.banged_name()); | 58 | item.insert_text(self.banged_name()); |
60 | } | 59 | } |
61 | _ => { | 60 | _ => { |
62 | cov_mark::hit!(dont_insert_macro_call_parens_unncessary); | 61 | cov_mark::hit!(dont_insert_macro_call_parens_unncessary); |
63 | builder.insert_text(&self.name); | 62 | item.insert_text(&self.name); |
64 | } | 63 | } |
65 | }; | 64 | }; |
66 | 65 | ||
67 | Some(builder.build()) | 66 | Some(item.build()) |
68 | } | 67 | } |
69 | 68 | ||
70 | fn needs_bang(&self) -> bool { | 69 | fn needs_bang(&self) -> bool { |
diff --git a/crates/ide_completion/src/render/pattern.rs b/crates/ide_completion/src/render/pattern.rs index 4d8f2b17d..ca2926125 100644 --- a/crates/ide_completion/src/render/pattern.rs +++ b/crates/ide_completion/src/render/pattern.rs | |||
@@ -69,20 +69,19 @@ fn build_completion( | |||
69 | ctx: RenderContext<'_>, | 69 | ctx: RenderContext<'_>, |
70 | name: String, | 70 | name: String, |
71 | pat: String, | 71 | pat: String, |
72 | item: impl HasAttrs + Copy, | 72 | def: impl HasAttrs + Copy, |
73 | ) -> CompletionItem { | 73 | ) -> CompletionItem { |
74 | let mut completion = CompletionItem::new(CompletionKind::Snippet, ctx.source_range(), name); | 74 | let mut item = CompletionItem::new(CompletionKind::Snippet, ctx.source_range(), name); |
75 | completion | 75 | item.kind(CompletionItemKind::Binding) |
76 | .kind(CompletionItemKind::Binding) | 76 | .set_documentation(ctx.docs(def)) |
77 | .set_documentation(ctx.docs(item)) | 77 | .set_deprecated(ctx.is_deprecated(def)) |
78 | .set_deprecated(ctx.is_deprecated(item)) | ||
79 | .detail(&pat); | 78 | .detail(&pat); |
80 | if let Some(snippet_cap) = ctx.snippet_cap() { | 79 | if let Some(snippet_cap) = ctx.snippet_cap() { |
81 | completion.insert_snippet(snippet_cap, pat); | 80 | item.insert_snippet(snippet_cap, pat); |
82 | } else { | 81 | } else { |
83 | completion.insert_text(pat); | 82 | item.insert_text(pat); |
84 | }; | 83 | }; |
85 | completion.build() | 84 | item.build() |
86 | } | 85 | } |
87 | 86 | ||
88 | fn render_pat( | 87 | fn render_pat( |