From 6285fcc39b70bc92de5188a5eb64ee8d73fa8970 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 24 Feb 2019 17:23:54 +0300 Subject: complete fields in struct literals --- .../src/completion/complete_struct_literal.rs | 23 +++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'crates') 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}; use crate::completion::{CompletionContext, Completions, CompletionItem, CompletionItemKind}; use crate::completion::completion_item::CompletionKind; -/// Complete dot accesses, i.e. fields or methods (currently only fields). +/// Complete fields in fields literals. pub(super) fn complete_struct_literal(acc: &mut Completions, ctx: &CompletionContext) { let (function, struct_lit) = match (&ctx.function, ctx.struct_lit_syntax) { (Some(function), Some(struct_lit)) => (function, struct_lit), @@ -42,17 +42,16 @@ pub(super) fn complete_struct_literal(acc: &mut Completions, ctx: &CompletionCon #[cfg(test)] mod tests { - use crate::completion::*; - use crate::completion::completion_item::check_completion; + use insta::assert_debug_snapshot_matches; + use crate::completion::{CompletionItem, CompletionKind}; - fn check_ref_completion(name: &str, code: &str) { - check_completion(name, code, CompletionKind::Reference); + fn complete(code: &str) -> Vec { + crate::completion::completion_item::do_completion(code, CompletionKind::Reference) } #[test] fn test_struct_literal_field() { - check_ref_completion( - "test_struct_literal_field", + let completions = complete( r" struct A { the_field: u32 } fn foo() { @@ -60,5 +59,15 @@ mod tests { } ", ); + assert_debug_snapshot_matches!(completions, @r###"[ + CompletionItem { + label: "the_field", + source_range: [83; 86), + delete: [83; 86), + insert: "the_field", + kind: Field, + detail: "u32" + } +]"###); } } -- cgit v1.2.3