From dad8f1e064eda525b5b98750ac4b28e5c34b0726 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 11 Mar 2020 10:46:43 +0100 Subject: Introduce completion test utils --- crates/ra_ide/src/completion/test_utils.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 crates/ra_ide/src/completion/test_utils.rs (limited to 'crates/ra_ide/src/completion/test_utils.rs') diff --git a/crates/ra_ide/src/completion/test_utils.rs b/crates/ra_ide/src/completion/test_utils.rs new file mode 100644 index 000000000..136857315 --- /dev/null +++ b/crates/ra_ide/src/completion/test_utils.rs @@ -0,0 +1,29 @@ +//! Runs completion for testing purposes. + +use crate::{ + completion::{completion_item::CompletionKind, CompletionOptions}, + mock_analysis::{analysis_and_position, single_file_with_position}, + CompletionItem, +}; + +pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec { + do_completion_with_options(code, kind, &CompletionOptions::default()) +} + +pub(crate) fn do_completion_with_options( + code: &str, + kind: CompletionKind, + options: &CompletionOptions, +) -> Vec { + let (analysis, position) = if code.contains("//-") { + analysis_and_position(code) + } else { + single_file_with_position(code) + }; + let completions = analysis.completions(position, options).unwrap().unwrap(); + let completion_items: Vec = completions.into(); + let mut kind_completions: Vec = + completion_items.into_iter().filter(|c| c.completion_kind == kind).collect(); + kind_completions.sort_by_key(|c| c.label().to_owned()); + kind_completions +} -- cgit v1.2.3