From 9af525dbd69bb22c968ba42d758657b2ad9bdd37 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 24 Feb 2019 20:49:55 +0300 Subject: simplify --- crates/ra_ide_api/src/completion/complete_dot.rs | 8 ++-- crates/ra_ide_api/src/completion/complete_path.rs | 2 +- .../src/completion/complete_struct_literal.rs | 4 +- crates/ra_ide_api/src/completion/presentation.rs | 52 ++++++++++------------ 4 files changed, 31 insertions(+), 35 deletions(-) diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index a6b988062..be76b997e 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs @@ -1,6 +1,6 @@ use hir::{Ty, AdtDef}; -use crate::completion::{CompletionContext, Completions, CompletionKind}; +use crate::completion::{CompletionContext, Completions}; /// Complete dot accesses, i.e. fields or methods (currently only fields). pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) { @@ -28,7 +28,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) match def_id { AdtDef::Struct(s) => { for field in s.fields(ctx.db) { - acc.add_field(CompletionKind::Reference, ctx, field, substs); + acc.add_field(ctx, field, substs); } } @@ -38,7 +38,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) } Ty::Tuple(fields) => { for (i, ty) in fields.iter().enumerate() { - acc.add_pos_field(CompletionKind::Reference, ctx, i, ty); + acc.add_pos_field(ctx, i, ty); } } _ => {} @@ -50,7 +50,7 @@ fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty receiver.iterate_methods(ctx.db, |_ty, func| { let sig = func.signature(ctx.db); if sig.has_self_param() { - acc.add_function(CompletionKind::Reference, ctx, func); + acc.add_function(ctx, func); } None::<()> }); diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index f8595b5c4..d2f65310f 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs @@ -64,7 +64,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { hir::ImplItem::Method(func) => { let sig = func.signature(ctx.db); if !sig.has_self_param() { - acc.add_function(CompletionKind::Reference, ctx, func); + acc.add_function(ctx, func); } None::<()> } diff --git a/crates/ra_ide_api/src/completion/complete_struct_literal.rs b/crates/ra_ide_api/src/completion/complete_struct_literal.rs index c617bff5f..1b8fb0768 100644 --- a/crates/ra_ide_api/src/completion/complete_struct_literal.rs +++ b/crates/ra_ide_api/src/completion/complete_struct_literal.rs @@ -1,6 +1,6 @@ use hir::{Ty, AdtDef}; -use crate::completion::{CompletionContext, Completions, CompletionKind}; +use crate::completion::{CompletionContext, Completions}; /// Complete fields in fields literals. pub(super) fn complete_struct_literal(acc: &mut Completions, ctx: &CompletionContext) { @@ -22,7 +22,7 @@ pub(super) fn complete_struct_literal(acc: &mut Completions, ctx: &CompletionCon match adt { AdtDef::Struct(s) => { for field in s.fields(ctx.db) { - acc.add_field(CompletionKind::Reference, ctx, field, substs); + acc.add_field(ctx, field, substs); } } diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index 057dbc21a..514f3b539 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs @@ -10,47 +10,43 @@ use crate::completion::{ impl Completions { pub(crate) fn add_field( &mut self, - kind: CompletionKind, ctx: &CompletionContext, field: hir::StructField, substs: &hir::Substs, ) { - CompletionItem::new(kind, ctx.source_range(), field.name(ctx.db).to_string()) - .kind(CompletionItemKind::Field) - .detail(field.ty(ctx.db).subst(substs).to_string()) - .set_documentation(field.docs(ctx.db)) - .add_to(self); + CompletionItem::new( + CompletionKind::Reference, + ctx.source_range(), + field.name(ctx.db).to_string(), + ) + .kind(CompletionItemKind::Field) + .detail(field.ty(ctx.db).subst(substs).to_string()) + .set_documentation(field.docs(ctx.db)) + .add_to(self); } - pub(crate) fn add_pos_field( - &mut self, - kind: CompletionKind, - ctx: &CompletionContext, - field: usize, - ty: &hir::Ty, - ) { - CompletionItem::new(kind, ctx.source_range(), field.to_string()) + pub(crate) fn add_pos_field(&mut self, ctx: &CompletionContext, field: usize, ty: &hir::Ty) { + CompletionItem::new(CompletionKind::Reference, ctx.source_range(), field.to_string()) .kind(CompletionItemKind::Field) .detail(ty.to_string()) .add_to(self); } - pub(crate) fn add_function( - &mut self, - kind: CompletionKind, - ctx: &CompletionContext, - func: hir::Function, - ) { + pub(crate) fn add_function(&mut self, ctx: &CompletionContext, func: hir::Function) { let sig = func.signature(ctx.db); - let mut builder = CompletionItem::new(kind, ctx.source_range(), sig.name().to_string()) - .kind(if sig.has_self_param() { - CompletionItemKind::Method - } else { - CompletionItemKind::Function - }) - .set_documentation(func.docs(ctx.db)) - .set_detail(function_item_label(ctx, func)); + let mut builder = CompletionItem::new( + CompletionKind::Reference, + ctx.source_range(), + sig.name().to_string(), + ) + .kind(if sig.has_self_param() { + CompletionItemKind::Method + } else { + CompletionItemKind::Function + }) + .set_documentation(func.docs(ctx.db)) + .set_detail(function_item_label(ctx, func)); // If not an import, add parenthesis automatically. if ctx.use_item_syntax.is_none() && !ctx.is_call { tested_by!(inserts_parens_for_function_calls); -- cgit v1.2.3