aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-01-25 17:02:30 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-01-25 17:02:30 +0000
commitbce0c6267aab2e8ca33a3e78a1081736abbc1373 (patch)
treef836aa726e004bdd6b47345776b2c6ff34cc70a7 /crates/ra_ide_api
parentdc5ecf446991c65359cf49d52098fcec5f1a1f68 (diff)
parent9a97c10fdafd0148b0f198e28b9694876cd0d672 (diff)
Merge #644
644: EnumVariant details for completion r=matklad a=kjeremy Co-authored-by: Jeremy A. Kolb <[email protected]>
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r--crates/ra_ide_api/Cargo.toml1
-rw-r--r--crates/ra_ide_api/src/completion/complete_path.rs35
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__enum_variant.snap (renamed from crates/ra_ide_api/src/completion/snapshots/completion_item__reference_completion.snap)14
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__enum_variant_with_details.snap64
4 files changed, 108 insertions, 6 deletions
diff --git a/crates/ra_ide_api/Cargo.toml b/crates/ra_ide_api/Cargo.toml
index 61942bbbb..dfdddea50 100644
--- a/crates/ra_ide_api/Cargo.toml
+++ b/crates/ra_ide_api/Cargo.toml
@@ -6,6 +6,7 @@ authors = ["Aleksey Kladov <[email protected]>"]
6 6
7[dependencies] 7[dependencies]
8itertools = "0.8.0" 8itertools = "0.8.0"
9join_to_string = "0.1.3"
9log = "0.4.5" 10log = "0.4.5"
10relative-path = "0.4.0" 11relative-path = "0.4.0"
11rayon = "1.0.2" 12rayon = "1.0.2"
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}
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__reference_completion.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__enum_variant.snap
index e46f7807b..8c84439b2 100644
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__reference_completion.snap
+++ b/crates/ra_ide_api/src/completion/snapshots/completion_item__enum_variant.snap
@@ -1,8 +1,8 @@
1--- 1---
2created: "2019-01-23T23:49:43.278245900+00:00" 2created: "2019-01-25T16:44:04.640545300+00:00"
3creator: [email protected].1 3creator: [email protected].2
4expression: kind_completions 4expression: kind_completions
5source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs" 5source: crates/ra_ide_api/src/completion/completion_item.rs
6--- 6---
7[ 7[
8 CompletionItem { 8 CompletionItem {
@@ -11,7 +11,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
11 kind: Some( 11 kind: Some(
12 EnumVariant 12 EnumVariant
13 ), 13 ),
14 detail: None, 14 detail: Some(
15 "()"
16 ),
15 documentation: Some( 17 documentation: Some(
16 Documentation( 18 Documentation(
17 "Foo Variant" 19 "Foo Variant"
@@ -29,7 +31,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
29 kind: Some( 31 kind: Some(
30 EnumVariant 32 EnumVariant
31 ), 33 ),
32 detail: None, 34 detail: Some(
35 "(i32)"
36 ),
33 documentation: Some( 37 documentation: Some(
34 Documentation( 38 Documentation(
35 "Bar Variant with i32" 39 "Bar Variant with i32"
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__enum_variant_with_details.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__enum_variant_with_details.snap
new file mode 100644
index 000000000..384634517
--- /dev/null
+++ b/crates/ra_ide_api/src/completion/snapshots/completion_item__enum_variant_with_details.snap
@@ -0,0 +1,64 @@
1---
2created: "2019-01-25T16:44:04.641542400+00:00"
3creator: [email protected]
4expression: kind_completions
5source: crates/ra_ide_api/src/completion/completion_item.rs
6---
7[
8 CompletionItem {
9 completion_kind: Reference,
10 label: "Foo",
11 kind: Some(
12 EnumVariant
13 ),
14 detail: Some(
15 "()"
16 ),
17 documentation: Some(
18 Documentation(
19 "Foo Variant (empty)"
20 )
21 ),
22 lookup: None,
23 insert_text: None,
24 insert_text_format: PlainText,
25 source_range: [180; 180),
26 text_edit: None
27 },
28 CompletionItem {
29 completion_kind: Reference,
30 label: "Bar",
31 kind: Some(
32 EnumVariant
33 ),
34 detail: Some(
35 "(i32, u32)"
36 ),
37 documentation: Some(
38 Documentation(
39 "Bar Variant with i32 and u32"
40 )
41 ),
42 lookup: None,
43 insert_text: None,
44 insert_text_format: PlainText,
45 source_range: [180; 180),
46 text_edit: None
47 },
48 CompletionItem {
49 completion_kind: Reference,
50 label: "S",
51 kind: Some(
52 EnumVariant
53 ),
54 detail: Some(
55 "(S)"
56 ),
57 documentation: None,
58 lookup: None,
59 insert_text: None,
60 insert_text_format: PlainText,
61 source_range: [180; 180),
62 text_edit: None
63 }
64]