7978: Unify naming r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2021-03-12 09:23:04 +00:00 committed by GitHub
commit c0e9530fd0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 90 additions and 103 deletions

View file

@ -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)
}
}
}

View file

@ -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)
});
}

View file

@ -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)]

View file

@ -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(())

View file

@ -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)]

View file

@ -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

View file

@ -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)]

View file

@ -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);
}
}
}

View file

@ -145,34 +145,33 @@ impl<'a> Render<'a> {
fn add_field(&mut self, field: hir::Field, ty: &Type) -> CompletionItem {
let is_deprecated = self.ctx.is_deprecated(field);
let name = field.name(self.ctx.db());
let mut builder = CompletionItem::new(
let mut item = CompletionItem::new(
CompletionKind::Reference,
self.ctx.source_range(),
name.to_string(),
);
builder
.kind(SymbolKind::Field)
item.kind(SymbolKind::Field)
.detail(ty.display(self.ctx.db()).to_string())
.set_documentation(field.docs(self.ctx.db()))
.set_deprecated(is_deprecated);
if let Some(relevance) = compute_relevance(&self.ctx, &ty, &name.to_string()) {
builder.set_relevance(relevance);
item.set_relevance(relevance);
}
builder.build()
item.build()
}
fn add_tuple_field(&mut self, field: usize, ty: &Type) -> CompletionItem {
let mut builder = CompletionItem::new(
let mut item = CompletionItem::new(
CompletionKind::Reference,
self.ctx.source_range(),
field.to_string(),
);
builder.kind(SymbolKind::Field).detail(ty.display(self.ctx.db()).to_string());
item.kind(SymbolKind::Field).detail(ty.display(self.ctx.db()).to_string());
builder.build()
item.build()
}
fn render_resolution(

View file

@ -55,13 +55,12 @@ impl<'a> EnumRender<'a> {
}
fn render(self, import_to_add: Option<ImportEdit>) -> CompletionItem {
let mut builder = CompletionItem::new(
let mut item = CompletionItem::new(
CompletionKind::Reference,
self.ctx.source_range(),
self.qualified_name.clone(),
);
builder
.kind(SymbolKind::Variant)
item.kind(SymbolKind::Variant)
.set_documentation(self.variant.docs(self.ctx.db()))
.set_deprecated(self.ctx.is_deprecated(self.variant))
.add_import(import_to_add)
@ -70,12 +69,12 @@ impl<'a> EnumRender<'a> {
if self.variant_kind == StructKind::Tuple {
cov_mark::hit!(inserts_parens_for_tuple_enums);
let params = Params::Anonymous(self.variant.fields(self.ctx.db()).len());
builder.add_call_parens(self.ctx.completion, self.short_qualified_name, params);
item.add_call_parens(self.ctx.completion, self.short_qualified_name, params);
} else if self.path.is_some() {
builder.lookup_by(self.short_qualified_name);
item.lookup_by(self.short_qualified_name);
}
builder.build()
item.build()
}
fn detail(&self) -> String {

View file

@ -41,13 +41,12 @@ impl<'a> FunctionRender<'a> {
fn render(self, import_to_add: Option<ImportEdit>) -> CompletionItem {
let params = self.params();
let mut builder = CompletionItem::new(
let mut item = CompletionItem::new(
CompletionKind::Reference,
self.ctx.source_range(),
self.name.clone(),
);
builder
.kind(self.kind())
item.kind(self.kind())
.set_documentation(self.ctx.docs(self.func))
.set_deprecated(
self.ctx.is_deprecated(self.func) || self.ctx.is_deprecated_assoc_item(self.func),
@ -56,7 +55,7 @@ impl<'a> FunctionRender<'a> {
.add_call_parens(self.ctx.completion, self.name, params)
.add_import(import_to_add);
builder.build()
item.build()
}
fn detail(&self) -> String {

View file

@ -39,10 +39,9 @@ impl<'a> MacroRender<'a> {
}
fn render(&self, import_to_add: Option<ImportEdit>) -> Option<CompletionItem> {
let mut builder =
let mut item =
CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), &self.label());
builder
.kind(SymbolKind::Macro)
item.kind(SymbolKind::Macro)
.set_documentation(self.docs.clone())
.set_deprecated(self.ctx.is_deprecated(self.macro_))
.add_import(import_to_add)
@ -53,18 +52,18 @@ impl<'a> MacroRender<'a> {
Some(cap) if needs_bang => {
let snippet = self.snippet();
let lookup = self.lookup();
builder.insert_snippet(cap, snippet).lookup_by(lookup);
item.insert_snippet(cap, snippet).lookup_by(lookup);
}
None if needs_bang => {
builder.insert_text(self.banged_name());
item.insert_text(self.banged_name());
}
_ => {
cov_mark::hit!(dont_insert_macro_call_parens_unncessary);
builder.insert_text(&self.name);
item.insert_text(&self.name);
}
};
Some(builder.build())
Some(item.build())
}
fn needs_bang(&self) -> bool {

View file

@ -69,20 +69,19 @@ fn build_completion(
ctx: RenderContext<'_>,
name: String,
pat: String,
item: impl HasAttrs + Copy,
def: impl HasAttrs + Copy,
) -> CompletionItem {
let mut completion = CompletionItem::new(CompletionKind::Snippet, ctx.source_range(), name);
completion
.kind(CompletionItemKind::Binding)
.set_documentation(ctx.docs(item))
.set_deprecated(ctx.is_deprecated(item))
let mut item = CompletionItem::new(CompletionKind::Snippet, ctx.source_range(), name);
item.kind(CompletionItemKind::Binding)
.set_documentation(ctx.docs(def))
.set_deprecated(ctx.is_deprecated(def))
.detail(&pat);
if let Some(snippet_cap) = ctx.snippet_cap() {
completion.insert_snippet(snippet_cap, pat);
item.insert_snippet(snippet_cap, pat);
} else {
completion.insert_text(pat);
item.insert_text(pat);
};
completion.build()
item.build()
}
fn render_pat(