aboutsummaryrefslogtreecommitdiff
path: root/crates/completion/src/test_utils.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-10-26 19:06:34 +0000
committerGitHub <[email protected]>2020-10-26 19:06:34 +0000
commitd10e2a04c8a5ff157acd95bc7458d36d9f396390 (patch)
treefb68b034d7e56053e5d1b4302e2996f64b024e11 /crates/completion/src/test_utils.rs
parentd01e412eb1572676a33ad145f3370a7157dbc9df (diff)
parent357bf0cedc658b7c95952324fda4bbe7f41a3e6a (diff)
Merge #6351
6351: Organized completions r=popzxc a=popzxc This PR continues the work on refactoring of the `completions` crate. In this episode: - Actual completions methods are encapsulated into `completions` module, so they aren't mixed with the rest of the code. - Name duplication was removed (`complete_attribute` => `completions::attribute`, `completion_context` => `context`). - `Completions` structure was moved from `item` module to the `completions`. - `presentation` module was removed, as it was basically a module with `impl` for `Completions`. - Code approaches were a bit unified here and there. Co-authored-by: Igor Aleksanov <[email protected]>
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}