diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_ide_api/src/completion/presentation.rs | 23 |
1 files changed, 15 insertions, 8 deletions
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 { | |||
50 | ScopeDef::ModuleDef(Function(func)) => { | 50 | ScopeDef::ModuleDef(Function(func)) => { |
51 | return self.add_function_with_name(ctx, Some(local_name), *func); | 51 | return self.add_function_with_name(ctx, Some(local_name), *func); |
52 | } | 52 | } |
53 | ScopeDef::ModuleDef(Adt(hir::Adt::Struct(it))) => { | 53 | ScopeDef::ModuleDef(Adt(adt)) => { |
54 | (CompletionItemKind::Struct, it.docs(ctx.db)) | 54 | return self.add_adt_with_name(ctx, local_name, *adt); |
55 | } | ||
56 | ScopeDef::ModuleDef(Adt(hir::Adt::Union(it))) => { | ||
57 | (CompletionItemKind::Struct, it.docs(ctx.db)) | ||
58 | } | ||
59 | ScopeDef::ModuleDef(Adt(hir::Adt::Enum(it))) => { | ||
60 | (CompletionItemKind::Enum, it.docs(ctx.db)) | ||
61 | } | 55 | } |
62 | ScopeDef::ModuleDef(EnumVariant(it)) => { | 56 | ScopeDef::ModuleDef(EnumVariant(it)) => { |
63 | (CompletionItemKind::EnumVariant, it.docs(ctx.db)) | 57 | (CompletionItemKind::EnumVariant, it.docs(ctx.db)) |
@@ -173,6 +167,19 @@ impl Completions { | |||
173 | self.add(builder) | 167 | self.add(builder) |
174 | } | 168 | } |
175 | 169 | ||
170 | fn add_adt_with_name(&mut self, ctx: &CompletionContext, name: String, adt: hir::Adt) { | ||
171 | let builder = CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name); | ||
172 | |||
173 | let (kind, docs) = match adt { | ||
174 | hir::Adt::Struct(it) => (CompletionItemKind::Struct, it.docs(ctx.db)), | ||
175 | // FIXME: add CompletionItemKind::Union | ||
176 | hir::Adt::Union(it) => (CompletionItemKind::Struct, it.docs(ctx.db)), | ||
177 | hir::Adt::Enum(it) => (CompletionItemKind::Enum, it.docs(ctx.db)), | ||
178 | }; | ||
179 | |||
180 | builder.kind(kind).set_documentation(docs).add_to(self) | ||
181 | } | ||
182 | |||
176 | pub(crate) fn add_const(&mut self, ctx: &CompletionContext, constant: hir::Const) { | 183 | pub(crate) fn add_const(&mut self, ctx: &CompletionContext, constant: hir::Const) { |
177 | let ast_node = constant.source(ctx.db).ast; | 184 | let ast_node = constant.source(ctx.db).ast; |
178 | let name = match ast_node.name() { | 185 | let name = match ast_node.name() { |