From 2f85a640a2698fbd31155172218a91d2e986fd47 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 8 Oct 2019 20:32:19 +0300 Subject: refactor --- crates/ra_ide_api/src/completion/presentation.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'crates') diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index eb480a775..9946db4ca 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs @@ -50,14 +50,8 @@ impl Completions { ScopeDef::ModuleDef(Function(func)) => { return self.add_function_with_name(ctx, Some(local_name), *func); } - ScopeDef::ModuleDef(Adt(hir::Adt::Struct(it))) => { - (CompletionItemKind::Struct, it.docs(ctx.db)) - } - ScopeDef::ModuleDef(Adt(hir::Adt::Union(it))) => { - (CompletionItemKind::Struct, it.docs(ctx.db)) - } - ScopeDef::ModuleDef(Adt(hir::Adt::Enum(it))) => { - (CompletionItemKind::Enum, it.docs(ctx.db)) + ScopeDef::ModuleDef(Adt(adt)) => { + return self.add_adt_with_name(ctx, local_name, *adt); } ScopeDef::ModuleDef(EnumVariant(it)) => { (CompletionItemKind::EnumVariant, it.docs(ctx.db)) @@ -173,6 +167,19 @@ impl Completions { self.add(builder) } + fn add_adt_with_name(&mut self, ctx: &CompletionContext, name: String, adt: hir::Adt) { + let builder = CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name); + + let (kind, docs) = match adt { + hir::Adt::Struct(it) => (CompletionItemKind::Struct, it.docs(ctx.db)), + // FIXME: add CompletionItemKind::Union + hir::Adt::Union(it) => (CompletionItemKind::Struct, it.docs(ctx.db)), + hir::Adt::Enum(it) => (CompletionItemKind::Enum, it.docs(ctx.db)), + }; + + builder.kind(kind).set_documentation(docs).add_to(self) + } + pub(crate) fn add_const(&mut self, ctx: &CompletionContext, constant: hir::Const) { let ast_node = constant.source(ctx.db).ast; let name = match ast_node.name() { -- cgit v1.2.3