From 357667104371d446cc029267e8095365c17ba085 Mon Sep 17 00:00:00 2001 From: Mikhail Rakhmanov Date: Fri, 12 Jun 2020 20:30:57 +0200 Subject: Rewrite snapshot checks --- crates/ra_ide/src/completion/test_utils.rs | 52 ++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 17 deletions(-) (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 index f439f974d..c660de7b1 100644 --- a/crates/ra_ide/src/completion/test_utils.rs +++ b/crates/ra_ide/src/completion/test_utils.rs @@ -3,7 +3,7 @@ use crate::{ completion::{completion_item::CompletionKind, CompletionConfig}, mock_analysis::{analysis_and_position, single_file_with_position}, - CompletionItem, FilePosition, + CompletionItem, }; use hir::Semantics; use ra_syntax::{AstNode, NodeOrToken, SyntaxElement}; @@ -12,11 +12,8 @@ pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec (FilePosition, Vec) { - do_completion_with_options_and_position(code, kind, &CompletionConfig::default()) +pub(crate) fn get_completions(code: &str, kind: CompletionKind) -> Vec { + get_completions_with_options(code, kind, &CompletionConfig::default()) } pub(crate) fn do_completion_with_options( @@ -24,25 +21,46 @@ pub(crate) fn do_completion_with_options( kind: CompletionKind, options: &CompletionConfig, ) -> Vec { - do_completion_with_options_and_position(code, kind, options).1 + let mut kind_completions: Vec = get_all_completion_items(code, options) + .into_iter() + .filter(|c| c.completion_kind == kind) + .collect(); + kind_completions.sort_by_key(|c| c.label().to_owned()); + kind_completions } -pub(crate) fn do_completion_with_options_and_position( - code: &str, - kind: CompletionKind, - options: &CompletionConfig, -) -> (FilePosition, Vec) { +fn get_all_completion_items(code: &str, options: &CompletionConfig) -> Vec { let (analysis, position) = if code.contains("//-") { analysis_and_position(code) } else { single_file_with_position(code) }; - let completions = analysis.completions(options, position).unwrap().unwrap(); - let completion_items: Vec = completions.into(); - let mut kind_completions: Vec = - completion_items.into_iter().filter(|c| c.completion_kind == kind).collect(); + analysis.completions(options, position).unwrap().unwrap().into() +} + +pub(crate) fn get_all_completions(code: &str, options: &CompletionConfig) -> Vec { + let mut kind_completions = get_all_completion_items(code, options); + kind_completions.sort_by_key(|c| c.label().to_owned()); + kind_completions + .into_iter() + .map(|it| format!("{} {}", it.kind().unwrap().tag(), it.label())) + .collect() +} + +pub(crate) fn get_completions_with_options( + code: &str, + kind: CompletionKind, + options: &CompletionConfig, +) -> Vec { + let mut kind_completions: Vec = get_all_completion_items(code, options) + .into_iter() + .filter(|c| c.completion_kind == kind) + .collect(); kind_completions.sort_by_key(|c| c.label().to_owned()); - (position, kind_completions) + kind_completions + .into_iter() + .map(|it| format!("{} {}", it.kind().unwrap().tag(), it.label())) + .collect() } pub(crate) fn check_pattern_is_applicable(code: &str, check: fn(SyntaxElement) -> bool) { -- cgit v1.2.3