aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/completion/complete_path.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/completion/complete_path.rs')
-rw-r--r--crates/ra_ide_api/src/completion/complete_path.rs35
1 files changed, 34 insertions, 1 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs
index e3f1d42f8..172aedf95 100644
--- a/crates/ra_ide_api/src/completion/complete_path.rs
+++ b/crates/ra_ide_api/src/completion/complete_path.rs
@@ -1,3 +1,5 @@
1use join_to_string::join;
2
1use crate::{ 3use crate::{
2 completion::{CompletionItem, CompletionItemKind, Completions, CompletionKind, CompletionContext}, 4 completion::{CompletionItem, CompletionItemKind, Completions, CompletionKind, CompletionContext},
3}; 5};
@@ -29,6 +31,15 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
29 hir::ModuleDef::Enum(e) => { 31 hir::ModuleDef::Enum(e) => {
30 e.variants(ctx.db).into_iter().for_each(|variant| { 32 e.variants(ctx.db).into_iter().for_each(|variant| {
31 if let Some(name) = variant.name(ctx.db) { 33 if let Some(name) = variant.name(ctx.db) {
34 let detail_types = variant
35 .fields(ctx.db)
36 .into_iter()
37 .map(|field| field.ty(ctx.db));
38 let detail = join(detail_types)
39 .separator(", ")
40 .surround_with("(", ")")
41 .to_string();
42
32 CompletionItem::new( 43 CompletionItem::new(
33 CompletionKind::Reference, 44 CompletionKind::Reference,
34 ctx.source_range(), 45 ctx.source_range(),
@@ -36,6 +47,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
36 ) 47 )
37 .kind(CompletionItemKind::EnumVariant) 48 .kind(CompletionItemKind::EnumVariant)
38 .set_documentation(variant.docs(ctx.db)) 49 .set_documentation(variant.docs(ctx.db))
50 .set_detail(Some(detail))
39 .add_to(acc) 51 .add_to(acc)
40 } 52 }
41 }); 53 });
@@ -116,7 +128,7 @@ mod tests {
116 #[test] 128 #[test]
117 fn completes_enum_variant() { 129 fn completes_enum_variant() {
118 check_reference_completion( 130 check_reference_completion(
119 "reference_completion", 131 "enum_variant",
120 " 132 "
121 //- /lib.rs 133 //- /lib.rs
122 /// An enum 134 /// An enum
@@ -130,4 +142,25 @@ mod tests {
130 ", 142 ",
131 ); 143 );
132 } 144 }
145
146 #[test]
147 fn completes_enum_variant_with_details() {
148 check_reference_completion(
149 "enum_variant_with_details",
150 "
151 //- /lib.rs
152 struct S { field: u32 }
153 /// An enum
154 enum E {
155 /// Foo Variant (empty)
156 Foo,
157 /// Bar Variant with i32 and u32
158 Bar(i32, u32),
159 ///
160 S(S),
161 }
162 fn foo() { let _ = E::<|> }
163 ",
164 );
165 }
133} 166}