aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src/completions
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-03-12 09:12:32 +0000
committerAleksey Kladov <[email protected]>2021-03-12 09:22:45 +0000
commit7e217a42e1c2dfd26defb9f448d8b0c57c7fc1a4 (patch)
tree9bb8c4b78a4525ecf758a2106254bf135d8a68f3 /crates/ide_completion/src/completions
parentc01ef6eabab1fa70d3fdfed9c565fadec9f0a5ed (diff)
Unify naming
Diffstat (limited to 'crates/ide_completion/src/completions')
-rw-r--r--crates/ide_completion/src/completions/attribute.rs18
-rw-r--r--crates/ide_completion/src/completions/fn_param.rs6
-rw-r--r--crates/ide_completion/src/completions/keyword.rs36
-rw-r--r--crates/ide_completion/src/completions/mod_.rs7
-rw-r--r--crates/ide_completion/src/completions/postfix.rs8
-rw-r--r--crates/ide_completion/src/completions/record.rs6
-rw-r--r--crates/ide_completion/src/completions/snippet.rs22
-rw-r--r--crates/ide_completion/src/completions/trait_impl.rs27
8 files changed, 61 insertions, 69 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
166fn add_keyword(ctx: &CompletionContext, acc: &mut Completions, kw: &str, snippet: &str) { 164fn 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
10fn snippet(ctx: &CompletionContext, cap: SnippetCap, label: &str, snippet: &str) -> Builder { 10fn 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
15pub(crate) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionContext) { 16pub(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
197fn add_const_impl( 195fn 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}