diff options
Diffstat (limited to 'crates/completion/src/test_utils.rs')
-rw-r--r-- | crates/completion/src/test_utils.rs | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/crates/completion/src/test_utils.rs b/crates/completion/src/test_utils.rs index eb0c16f52..3f4b9d4ac 100644 --- a/crates/completion/src/test_utils.rs +++ b/crates/completion/src/test_utils.rs | |||
@@ -1,8 +1,11 @@ | |||
1 | //! Runs completion for testing purposes. | 1 | //! Runs completion for testing purposes. |
2 | 2 | ||
3 | use hir::Semantics; | 3 | use hir::Semantics; |
4 | use ide_db::base_db::{fixture::ChangeFixture, FileLoader, FilePosition}; | 4 | use ide_db::{ |
5 | use ide_db::RootDatabase; | 5 | base_db::{fixture::ChangeFixture, FileLoader, FilePosition}, |
6 | helpers::{insert_use::MergeBehavior, SnippetCap}, | ||
7 | RootDatabase, | ||
8 | }; | ||
6 | use itertools::Itertools; | 9 | use itertools::Itertools; |
7 | use stdx::{format_to, trim_indent}; | 10 | use stdx::{format_to, trim_indent}; |
8 | use syntax::{AstNode, NodeOrToken, SyntaxElement}; | 11 | use syntax::{AstNode, NodeOrToken, SyntaxElement}; |
@@ -10,12 +13,21 @@ use test_utils::{assert_eq_text, RangeOrOffset}; | |||
10 | 13 | ||
11 | use crate::{item::CompletionKind, CompletionConfig, CompletionItem}; | 14 | use crate::{item::CompletionKind, CompletionConfig, CompletionItem}; |
12 | 15 | ||
13 | /// Creates analysis from a multi-file fixture, returns positions marked with <|>. | 16 | pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig { |
17 | enable_postfix_completions: true, | ||
18 | enable_autoimport_completions: true, | ||
19 | add_call_parenthesis: true, | ||
20 | add_call_argument_snippets: true, | ||
21 | snippet_cap: SnippetCap::new(true), | ||
22 | merge: Some(MergeBehavior::Full), | ||
23 | }; | ||
24 | |||
25 | /// Creates analysis from a multi-file fixture, returns positions marked with $0. | ||
14 | pub(crate) fn position(ra_fixture: &str) -> (RootDatabase, FilePosition) { | 26 | pub(crate) fn position(ra_fixture: &str) -> (RootDatabase, FilePosition) { |
15 | let change_fixture = ChangeFixture::parse(ra_fixture); | 27 | let change_fixture = ChangeFixture::parse(ra_fixture); |
16 | let mut database = RootDatabase::default(); | 28 | let mut database = RootDatabase::default(); |
17 | database.apply_change(change_fixture.change); | 29 | database.apply_change(change_fixture.change); |
18 | let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker (<|>)"); | 30 | let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker ($0)"); |
19 | let offset = match range_or_offset { | 31 | let offset = match range_or_offset { |
20 | RangeOrOffset::Range(_) => panic!(), | 32 | RangeOrOffset::Range(_) => panic!(), |
21 | RangeOrOffset::Offset(it) => it, | 33 | RangeOrOffset::Offset(it) => it, |
@@ -24,7 +36,7 @@ pub(crate) fn position(ra_fixture: &str) -> (RootDatabase, FilePosition) { | |||
24 | } | 36 | } |
25 | 37 | ||
26 | pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec<CompletionItem> { | 38 | pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec<CompletionItem> { |
27 | do_completion_with_config(CompletionConfig::default(), code, kind) | 39 | do_completion_with_config(TEST_CONFIG, code, kind) |
28 | } | 40 | } |
29 | 41 | ||
30 | pub(crate) fn do_completion_with_config( | 42 | pub(crate) fn do_completion_with_config( |
@@ -39,7 +51,7 @@ pub(crate) fn do_completion_with_config( | |||
39 | } | 51 | } |
40 | 52 | ||
41 | pub(crate) fn completion_list(code: &str, kind: CompletionKind) -> String { | 53 | pub(crate) fn completion_list(code: &str, kind: CompletionKind) -> String { |
42 | completion_list_with_config(CompletionConfig::default(), code, kind) | 54 | completion_list_with_config(TEST_CONFIG, code, kind) |
43 | } | 55 | } |
44 | 56 | ||
45 | pub(crate) fn completion_list_with_config( | 57 | pub(crate) fn completion_list_with_config( |
@@ -76,7 +88,7 @@ fn monospace_width(s: &str) -> usize { | |||
76 | } | 88 | } |
77 | 89 | ||
78 | pub(crate) fn check_edit(what: &str, ra_fixture_before: &str, ra_fixture_after: &str) { | 90 | pub(crate) fn check_edit(what: &str, ra_fixture_before: &str, ra_fixture_after: &str) { |
79 | check_edit_with_config(CompletionConfig::default(), what, ra_fixture_before, ra_fixture_after) | 91 | check_edit_with_config(TEST_CONFIG, what, ra_fixture_before, ra_fixture_after) |
80 | } | 92 | } |
81 | 93 | ||
82 | pub(crate) fn check_edit_with_config( | 94 | pub(crate) fn check_edit_with_config( |