diff options
Diffstat (limited to 'crates/ra_ide_api/src/completion/presentation.rs')
-rw-r--r-- | crates/ra_ide_api/src/completion/presentation.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index 514f3b539..bc2cb4a0f 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs | |||
@@ -1,4 +1,5 @@ | |||
1 | //! This modules takes care of rendering various defenitions as completion items. | 1 | //! This modules takes care of rendering various defenitions as completion items. |
2 | use join_to_string::join; | ||
2 | use test_utils::tested_by; | 3 | use test_utils::tested_by; |
3 | use hir::Docs; | 4 | use hir::Docs; |
4 | 5 | ||
@@ -60,6 +61,21 @@ impl Completions { | |||
60 | } | 61 | } |
61 | self.add(builder) | 62 | self.add(builder) |
62 | } | 63 | } |
64 | |||
65 | pub(crate) fn add_enum_variant(&mut self, ctx: &CompletionContext, variant: hir::EnumVariant) { | ||
66 | let name = match variant.name(ctx.db) { | ||
67 | Some(it) => it, | ||
68 | None => return, | ||
69 | }; | ||
70 | let detail_types = variant.fields(ctx.db).into_iter().map(|field| field.ty(ctx.db)); | ||
71 | let detail = join(detail_types).separator(", ").surround_with("(", ")").to_string(); | ||
72 | |||
73 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.to_string()) | ||
74 | .kind(CompletionItemKind::EnumVariant) | ||
75 | .set_documentation(variant.docs(ctx.db)) | ||
76 | .detail(detail) | ||
77 | .add_to(self); | ||
78 | } | ||
63 | } | 79 | } |
64 | 80 | ||
65 | fn function_item_label(ctx: &CompletionContext, function: hir::Function) -> Option<String> { | 81 | fn function_item_label(ctx: &CompletionContext, function: hir::Function) -> Option<String> { |