aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_ide_api/src/completion/complete_struct_literal.rs23
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};
3use crate::completion::{CompletionContext, Completions, CompletionItem, CompletionItemKind}; 3use crate::completion::{CompletionContext, Completions, CompletionItem, CompletionItemKind};
4use crate::completion::completion_item::CompletionKind; 4use 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.
7pub(super) fn complete_struct_literal(acc: &mut Completions, ctx: &CompletionContext) { 7pub(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)]
44mod tests { 44mod 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}