diff options
author | Aleksey Kladov <[email protected]> | 2019-02-24 14:23:54 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-02-24 14:39:08 +0000 |
commit | 6285fcc39b70bc92de5188a5eb64ee8d73fa8970 (patch) | |
tree | 00eb88738994ca74d81ab105162b2fcae64987ee /crates | |
parent | 65a2be49539375502ca95c8da455f50f580df2e3 (diff) |
complete fields in struct literals
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_struct_literal.rs | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_struct_literal.rs b/crates/ra_ide_api/src/completion/complete_struct_literal.rs index 893056c2b..f8dd2baad 100644 --- a/crates/ra_ide_api/src/completion/complete_struct_literal.rs +++ b/crates/ra_ide_api/src/completion/complete_struct_literal.rs | |||
@@ -3,7 +3,7 @@ use hir::{Ty, AdtDef, Docs}; | |||
3 | use crate::completion::{CompletionContext, Completions, CompletionItem, CompletionItemKind}; | 3 | use crate::completion::{CompletionContext, Completions, CompletionItem, CompletionItemKind}; |
4 | use crate::completion::completion_item::CompletionKind; | 4 | use crate::completion::completion_item::CompletionKind; |
5 | 5 | ||
6 | /// Complete dot accesses, i.e. fields or methods (currently only fields). | 6 | /// Complete fields in fields literals. |
7 | pub(super) fn complete_struct_literal(acc: &mut Completions, ctx: &CompletionContext) { | 7 | pub(super) fn complete_struct_literal(acc: &mut Completions, ctx: &CompletionContext) { |
8 | let (function, struct_lit) = match (&ctx.function, ctx.struct_lit_syntax) { | 8 | let (function, struct_lit) = match (&ctx.function, ctx.struct_lit_syntax) { |
9 | (Some(function), Some(struct_lit)) => (function, struct_lit), | 9 | (Some(function), Some(struct_lit)) => (function, struct_lit), |
@@ -42,17 +42,16 @@ pub(super) fn complete_struct_literal(acc: &mut Completions, ctx: &CompletionCon | |||
42 | 42 | ||
43 | #[cfg(test)] | 43 | #[cfg(test)] |
44 | mod tests { | 44 | mod tests { |
45 | use crate::completion::*; | 45 | use insta::assert_debug_snapshot_matches; |
46 | use crate::completion::completion_item::check_completion; | 46 | use crate::completion::{CompletionItem, CompletionKind}; |
47 | 47 | ||
48 | fn check_ref_completion(name: &str, code: &str) { | 48 | fn complete(code: &str) -> Vec<CompletionItem> { |
49 | check_completion(name, code, CompletionKind::Reference); | 49 | crate::completion::completion_item::do_completion(code, CompletionKind::Reference) |
50 | } | 50 | } |
51 | 51 | ||
52 | #[test] | 52 | #[test] |
53 | fn test_struct_literal_field() { | 53 | fn test_struct_literal_field() { |
54 | check_ref_completion( | 54 | let completions = complete( |
55 | "test_struct_literal_field", | ||
56 | r" | 55 | r" |
57 | struct A { the_field: u32 } | 56 | struct A { the_field: u32 } |
58 | fn foo() { | 57 | fn foo() { |
@@ -60,5 +59,15 @@ mod tests { | |||
60 | } | 59 | } |
61 | ", | 60 | ", |
62 | ); | 61 | ); |
62 | assert_debug_snapshot_matches!(completions, @r###"[ | ||
63 | CompletionItem { | ||
64 | label: "the_field", | ||
65 | source_range: [83; 86), | ||
66 | delete: [83; 86), | ||
67 | insert: "the_field", | ||
68 | kind: Field, | ||
69 | detail: "u32" | ||
70 | } | ||
71 | ]"###); | ||
63 | } | 72 | } |
64 | } | 73 | } |