aboutsummaryrefslogtreecommitdiff
path: root/crates/completion/src/test_utils.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/completion/src/test_utils.rs')
-rw-r--r--crates/completion/src/test_utils.rs19
1 files changed, 6 insertions, 13 deletions
diff --git a/crates/completion/src/test_utils.rs b/crates/completion/src/test_utils.rs
index b02556797..4c1b1a839 100644
--- a/crates/completion/src/test_utils.rs
+++ b/crates/completion/src/test_utils.rs
@@ -8,7 +8,7 @@ use stdx::{format_to, trim_indent};
8use syntax::{AstNode, NodeOrToken, SyntaxElement}; 8use syntax::{AstNode, NodeOrToken, SyntaxElement};
9use test_utils::{assert_eq_text, RangeOrOffset}; 9use test_utils::{assert_eq_text, RangeOrOffset};
10 10
11use crate::{completion_item::CompletionKind, CompletionConfig, CompletionItem}; 11use crate::{item::CompletionKind, CompletionConfig, CompletionItem};
12 12
13/// Creates analysis from a multi-file fixture, returns positions marked with <|>. 13/// Creates analysis from a multi-file fixture, returns positions marked with <|>.
14pub(crate) fn position(ra_fixture: &str) -> (RootDatabase, FilePosition) { 14pub(crate) fn position(ra_fixture: &str) -> (RootDatabase, FilePosition) {
@@ -32,10 +32,8 @@ pub(crate) fn do_completion_with_config(
32 code: &str, 32 code: &str,
33 kind: CompletionKind, 33 kind: CompletionKind,
34) -> Vec<CompletionItem> { 34) -> Vec<CompletionItem> {
35 let mut kind_completions: Vec<CompletionItem> = get_all_completion_items(config, code) 35 let mut kind_completions: Vec<CompletionItem> =
36 .into_iter() 36 get_all_items(config, code).into_iter().filter(|c| c.completion_kind == kind).collect();
37 .filter(|c| c.completion_kind == kind)
38 .collect();
39 kind_completions.sort_by(|l, r| l.label().cmp(r.label())); 37 kind_completions.sort_by(|l, r| l.label().cmp(r.label()));
40 kind_completions 38 kind_completions
41} 39}
@@ -49,10 +47,8 @@ pub(crate) fn completion_list_with_config(
49 code: &str, 47 code: &str,
50 kind: CompletionKind, 48 kind: CompletionKind,
51) -> String { 49) -> String {
52 let mut kind_completions: Vec<CompletionItem> = get_all_completion_items(config, code) 50 let mut kind_completions: Vec<CompletionItem> =
53 .into_iter() 51 get_all_items(config, code).into_iter().filter(|c| c.completion_kind == kind).collect();
54 .filter(|c| c.completion_kind == kind)
55 .collect();
56 kind_completions.sort_by_key(|c| c.label().to_owned()); 52 kind_completions.sort_by_key(|c| c.label().to_owned());
57 let label_width = kind_completions 53 let label_width = kind_completions
58 .iter() 54 .iter()
@@ -121,10 +117,7 @@ pub(crate) fn check_pattern_is_not_applicable(code: &str, check: fn(SyntaxElemen
121 assert!(!check(NodeOrToken::Token(token))); 117 assert!(!check(NodeOrToken::Token(token)));
122} 118}
123 119
124pub(crate) fn get_all_completion_items( 120pub(crate) fn get_all_items(config: CompletionConfig, code: &str) -> Vec<CompletionItem> {
125 config: CompletionConfig,
126 code: &str,
127) -> Vec<CompletionItem> {
128 let (db, position) = position(code); 121 let (db, position) = position(code);
129 crate::completions(&db, &config, position).unwrap().into() 122 crate::completions(&db, &config, position).unwrap().into()
130} 123}