From 7e217a42e1c2dfd26defb9f448d8b0c57c7fc1a4 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 12 Mar 2021 12:12:32 +0300 Subject: Unify naming --- crates/ide_completion/src/completions/attribute.rs | 18 +++++------ crates/ide_completion/src/completions/fn_param.rs | 6 ++-- crates/ide_completion/src/completions/keyword.rs | 36 ++++++++++------------ crates/ide_completion/src/completions/mod_.rs | 7 ++--- crates/ide_completion/src/completions/postfix.rs | 8 ++--- crates/ide_completion/src/completions/record.rs | 6 ++-- crates/ide_completion/src/completions/snippet.rs | 22 ++++++------- .../ide_completion/src/completions/trait_impl.rs | 27 ++++++++-------- 8 files changed, 61 insertions(+), 69 deletions(-) (limited to 'crates/ide_completion/src/completions') 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: ); let lookup = components.join(", "); let label = components.iter().rev().join(", "); - let mut builder = + let mut item = CompletionItem::new(CompletionKind::Attribute, ctx.source_range(), label); - builder.lookup_by(lookup).kind(CompletionItemKind::Attribute); - builder.add_to(acc); + item.lookup_by(lookup).kind(CompletionItemKind::Attribute); + item.add_to(acc); } for custom_derive_name in get_derive_names_in_scope(ctx).difference(&existing_derives) { - let mut builder = CompletionItem::new( + let mut item = CompletionItem::new( CompletionKind::Attribute, ctx.source_range(), custom_derive_name, ); - builder.kind(CompletionItemKind::Attribute); - builder.add_to(acc); + item.kind(CompletionItemKind::Attribute); + item.add_to(acc); } } } @@ -197,13 +197,13 @@ fn complete_lint( .into_iter() .filter(|completion| !existing_lints.contains(completion.label)) { - let mut builder = CompletionItem::new( + let mut item = CompletionItem::new( CompletionKind::Attribute, ctx.source_range(), lint_completion.label, ); - builder.kind(CompletionItemKind::Attribute).detail(lint_completion.description); - builder.add_to(acc) + item.kind(CompletionItemKind::Attribute).detail(lint_completion.description); + item.add_to(acc) } } } 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) } params.into_iter().for_each(|(label, lookup)| { - let mut builder = CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label); - builder.kind(CompletionItemKind::Binding).lookup_by(lookup); - builder.add_to(acc) + let mut item = CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label); + item.kind(CompletionItemKind::Binding).lookup_by(lookup); + item.add_to(acc) }); } 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 if ctx.use_item_syntax.is_some() { if ctx.path_qual.is_none() { - let mut crate_builder = - CompletionItem::new(CompletionKind::Keyword, source_range, "crate::"); - crate_builder.kind(CompletionItemKind::Keyword).insert_text("crate::"); - crate_builder.add_to(acc); + let mut item = CompletionItem::new(CompletionKind::Keyword, source_range, "crate::"); + item.kind(CompletionItemKind::Keyword).insert_text("crate::"); + item.add_to(acc); } - let mut self_builder = CompletionItem::new(CompletionKind::Keyword, source_range, "self"); - self_builder.kind(CompletionItemKind::Keyword); - self_builder.add_to(acc); + let mut item = CompletionItem::new(CompletionKind::Keyword, source_range, "self"); + item.kind(CompletionItemKind::Keyword); + item.add_to(acc); if iter::successors(ctx.path_qual.clone(), |p| p.qualifier()) .all(|p| p.segment().and_then(|s| s.super_token()).is_some()) { - let mut super_builder = - CompletionItem::new(CompletionKind::Keyword, source_range, "super::"); - super_builder.kind(CompletionItemKind::Keyword).insert_text("super::"); - super_builder.add_to(acc); + let mut item = CompletionItem::new(CompletionKind::Keyword, source_range, "super::"); + item.kind(CompletionItemKind::Keyword).insert_text("super::"); + item.add_to(acc); } } @@ -34,10 +32,10 @@ pub(crate) fn complete_use_tree_keyword(acc: &mut Completions, ctx: &CompletionC if let Some(receiver) = &ctx.dot_receiver { if let Some(ty) = ctx.sema.type_of_expr(receiver) { if ty.impls_future(ctx.db) { - let mut builder = + let mut item = CompletionItem::new(CompletionKind::Keyword, ctx.source_range(), "await"); - builder.kind(CompletionItemKind::Keyword).detail("expr.await").insert_text("await"); - builder.add_to(acc); + item.kind(CompletionItemKind::Keyword).detail("expr.await").insert_text("await"); + item.add_to(acc); } }; } @@ -164,8 +162,8 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte } fn add_keyword(ctx: &CompletionContext, acc: &mut Completions, kw: &str, snippet: &str) { - let mut builder = CompletionItem::new(CompletionKind::Keyword, ctx.source_range(), kw); - builder.kind(CompletionItemKind::Keyword); + let mut item = CompletionItem::new(CompletionKind::Keyword, ctx.source_range(), kw); + item.kind(CompletionItemKind::Keyword); match ctx.config.snippet_cap { Some(cap) => { @@ -177,13 +175,13 @@ fn add_keyword(ctx: &CompletionContext, acc: &mut Completions, kw: &str, snippet } else { snippet }; - builder.insert_snippet(cap, snippet); + item.insert_snippet(cap, snippet); } None => { - builder.insert_text(if snippet.contains('$') { kw } else { snippet }); + item.insert_text(if snippet.contains('$') { kw } else { snippet }); } }; - acc.add(builder.build()); + item.add_to(acc); } #[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 if mod_under_caret.semicolon_token().is_none() { label.push(';'); } - let mut builder = - CompletionItem::new(CompletionKind::Magic, ctx.source_range(), &label); - builder.kind(SymbolKind::Module); - builder.add_to(acc) + let mut item = CompletionItem::new(CompletionKind::Magic, ctx.source_range(), &label); + item.kind(SymbolKind::Module); + item.add_to(acc) }); 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( let delete_range = TextRange::new(receiver_range.start(), ctx.source_range().end()); TextEdit::replace(delete_range, snippet.to_string()) }; - CompletionItem::new(CompletionKind::Postfix, ctx.source_range(), label) - .detail(detail) - .kind(CompletionItemKind::Snippet) - .snippet_edit(cap, edit) - .clone() + let mut item = CompletionItem::new(CompletionKind::Postfix, ctx.source_range(), label); + item.detail(detail).kind(CompletionItemKind::Snippet).snippet_edit(cap, edit); + item } #[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) -> let completion_text = completion_text .strip_prefix(ctx.token.to_string().as_str()) .unwrap_or(completion_text); - let mut builder = CompletionItem::new( + let mut item = CompletionItem::new( CompletionKind::Snippet, ctx.source_range(), "..Default::default()", ); - builder.insert_text(completion_text).kind(SymbolKind::Field); - acc.add(builder.build()); + item.insert_text(completion_text).kind(SymbolKind::Field); + item.add_to(acc); } 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::{ }; fn snippet(ctx: &CompletionContext, cap: SnippetCap, label: &str, snippet: &str) -> Builder { - let mut builder = CompletionItem::new(CompletionKind::Snippet, ctx.source_range(), label); - builder.insert_snippet(cap, snippet).kind(CompletionItemKind::Snippet).clone() + let mut item = CompletionItem::new(CompletionKind::Snippet, ctx.source_range(), label); + item.insert_snippet(cap, snippet).kind(CompletionItemKind::Snippet); + item } 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 None => return, }; - let mut test_module_builder = snippet( + let mut item = snippet( ctx, cap, "tmod (Test module)", @@ -49,10 +50,10 @@ mod tests { } }", ); - test_module_builder.lookup_by("tmod"); - test_module_builder.add_to(acc); + item.lookup_by("tmod"); + item.add_to(acc); - let mut test_function_builder = snippet( + let mut item = snippet( ctx, cap, "tfn (Test function)", @@ -62,12 +63,11 @@ fn ${1:feature}() { $0 }", ); - test_function_builder.lookup_by("tfn"); - test_function_builder.add_to(acc); + item.lookup_by("tfn"); + item.add_to(acc); - let macro_rules_builder = - snippet(ctx, cap, "macro_rules", "macro_rules! $1 {\n\t($2) => {\n\t\t$0\n\t};\n}"); - macro_rules_builder.add_to(acc); + let item = snippet(ctx, cap, "macro_rules", "macro_rules! $1 {\n\t($2) => {\n\t\t$0\n\t};\n}"); + item.add_to(acc); } #[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( format!("fn {}(..)", fn_name) }; - let mut builder = CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label); - builder.lookup_by(fn_name).set_documentation(func.docs(ctx.db)); + let mut item = CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label); + item.lookup_by(fn_name).set_documentation(func.docs(ctx.db)); let completion_kind = if func.self_param(ctx.db).is_some() { CompletionItemKind::Method @@ -160,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)); + item.snippet_edit(cap, TextEdit::replace(range, snippet)); } None => { let header = format!("{} {{", function_decl); - builder.text_edit(TextEdit::replace(range, header)); + item.text_edit(TextEdit::replace(range, header)); } }; - builder.kind(completion_kind); - builder.add_to(acc); + item.kind(completion_kind); + item.add_to(acc); } } @@ -184,14 +184,12 @@ fn add_type_alias_impl( let range = TextRange::new(type_def_node.text_range().start(), ctx.source_range().end()); - let mut builder = - CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone()); - builder - .text_edit(TextEdit::replace(range, snippet)) + let mut item = CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone()); + item.text_edit(TextEdit::replace(range, snippet)) .lookup_by(alias_name) .kind(SymbolKind::TypeAlias) .set_documentation(type_alias.docs(ctx.db)); - builder.add_to(acc); + item.add_to(acc); } fn add_const_impl( @@ -209,14 +207,13 @@ fn add_const_impl( let range = TextRange::new(const_def_node.text_range().start(), ctx.source_range().end()); - let mut builder = + let mut item = CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone()); - builder - .text_edit(TextEdit::replace(range, snippet)) + item.text_edit(TextEdit::replace(range, snippet)) .lookup_by(const_name) .kind(SymbolKind::Const) .set_documentation(const_.docs(ctx.db)); - builder.add_to(acc); + item.add_to(acc); } } } -- cgit v1.2.3