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.rs51
1 files changed, 50 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..b33ddcde5 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 });
@@ -54,6 +66,22 @@ mod tests {
54 } 66 }
55 67
56 #[test] 68 #[test]
69 fn completes_mod_with_docs() {
70 check_reference_completion(
71 "mod_with_docs",
72 r"
73 use self::my<|>;
74
75 /// Some simple
76 /// docs describing `mod my`.
77 mod my {
78 struct Bar;
79 }
80 ",
81 );
82 }
83
84 #[test]
57 fn completes_use_item_starting_with_self() { 85 fn completes_use_item_starting_with_self() {
58 check_reference_completion( 86 check_reference_completion(
59 "use_item_starting_with_self", 87 "use_item_starting_with_self",
@@ -116,7 +144,7 @@ mod tests {
116 #[test] 144 #[test]
117 fn completes_enum_variant() { 145 fn completes_enum_variant() {
118 check_reference_completion( 146 check_reference_completion(
119 "reference_completion", 147 "enum_variant",
120 " 148 "
121 //- /lib.rs 149 //- /lib.rs
122 /// An enum 150 /// An enum
@@ -130,4 +158,25 @@ mod tests {
130 ", 158 ",
131 ); 159 );
132 } 160 }
161
162 #[test]
163 fn completes_enum_variant_with_details() {
164 check_reference_completion(
165 "enum_variant_with_details",
166 "
167 //- /lib.rs
168 struct S { field: u32 }
169 /// An enum
170 enum E {
171 /// Foo Variant (empty)
172 Foo,
173 /// Bar Variant with i32 and u32
174 Bar(i32, u32),
175 ///
176 S(S),
177 }
178 fn foo() { let _ = E::<|> }
179 ",
180 );
181 }
133} 182}