diff options
author | Aleksey Kladov <[email protected]> | 2021-01-06 17:43:46 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2021-01-06 18:22:24 +0000 |
commit | f8a056117898c56d34d1758455bc54df50e2e426 (patch) | |
tree | 429e2c7284476213432b66b02ab9b76f6525eb92 /crates/completion/src/completions | |
parent | 7ae4b8bdb62735ee767dff25ce1485ae8bffe199 (diff) |
Align config's API with usage
The config now is mostly immutable, optimize for that.
Diffstat (limited to 'crates/completion/src/completions')
4 files changed, 17 insertions, 19 deletions
diff --git a/crates/completion/src/completions/postfix.rs b/crates/completion/src/completions/postfix.rs index 3883d6d21..4888f518a 100644 --- a/crates/completion/src/completions/postfix.rs +++ b/crates/completion/src/completions/postfix.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | mod format_like; | 3 | mod format_like; |
4 | 4 | ||
5 | use ide_db::ty_filter::TryEnum; | 5 | use ide_db::{helpers::SnippetCap, ty_filter::TryEnum}; |
6 | use syntax::{ | 6 | use syntax::{ |
7 | ast::{self, AstNode, AstToken}, | 7 | ast::{self, AstNode, AstToken}, |
8 | SyntaxKind::{BLOCK_EXPR, EXPR_STMT}, | 8 | SyntaxKind::{BLOCK_EXPR, EXPR_STMT}, |
@@ -10,9 +10,8 @@ use syntax::{ | |||
10 | }; | 10 | }; |
11 | use text_edit::TextEdit; | 11 | use text_edit::TextEdit; |
12 | 12 | ||
13 | use self::format_like::add_format_like_completions; | ||
14 | use crate::{ | 13 | use crate::{ |
15 | config::SnippetCap, | 14 | completions::postfix::format_like::add_format_like_completions, |
16 | context::CompletionContext, | 15 | context::CompletionContext, |
17 | item::{Builder, CompletionKind}, | 16 | item::{Builder, CompletionKind}, |
18 | CompletionItem, CompletionItemKind, Completions, | 17 | CompletionItem, CompletionItemKind, Completions, |
diff --git a/crates/completion/src/completions/postfix/format_like.rs b/crates/completion/src/completions/postfix/format_like.rs index def4b13fb..3afc63021 100644 --- a/crates/completion/src/completions/postfix/format_like.rs +++ b/crates/completion/src/completions/postfix/format_like.rs | |||
@@ -14,12 +14,11 @@ | |||
14 | // + `logw` -> `log::warn!(...)` | 14 | // + `logw` -> `log::warn!(...)` |
15 | // + `loge` -> `log::error!(...)` | 15 | // + `loge` -> `log::error!(...)` |
16 | 16 | ||
17 | use crate::{ | 17 | use ide_db::helpers::SnippetCap; |
18 | completions::postfix::postfix_snippet, config::SnippetCap, context::CompletionContext, | ||
19 | Completions, | ||
20 | }; | ||
21 | use syntax::ast::{self, AstToken}; | 18 | use syntax::ast::{self, AstToken}; |
22 | 19 | ||
20 | use crate::{completions::postfix::postfix_snippet, context::CompletionContext, Completions}; | ||
21 | |||
23 | /// Mapping ("postfix completion item" => "macro to use") | 22 | /// Mapping ("postfix completion item" => "macro to use") |
24 | static KINDS: &[(&str, &str)] = &[ | 23 | static KINDS: &[(&str, &str)] = &[ |
25 | ("format", "format!"), | 24 | ("format", "format!"), |
diff --git a/crates/completion/src/completions/snippet.rs b/crates/completion/src/completions/snippet.rs index 842590130..b5e704696 100644 --- a/crates/completion/src/completions/snippet.rs +++ b/crates/completion/src/completions/snippet.rs | |||
@@ -1,8 +1,10 @@ | |||
1 | //! This file provides snippet completions, like `pd` => `eprintln!(...)`. | 1 | //! This file provides snippet completions, like `pd` => `eprintln!(...)`. |
2 | 2 | ||
3 | use ide_db::helpers::SnippetCap; | ||
4 | |||
3 | use crate::{ | 5 | use crate::{ |
4 | config::SnippetCap, item::Builder, CompletionContext, CompletionItem, CompletionItemKind, | 6 | item::Builder, CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, |
5 | CompletionKind, Completions, | 7 | Completions, |
6 | }; | 8 | }; |
7 | 9 | ||
8 | fn snippet(ctx: &CompletionContext, cap: SnippetCap, label: &str, snippet: &str) -> Builder { | 10 | fn snippet(ctx: &CompletionContext, cap: SnippetCap, label: &str, snippet: &str) -> Builder { |
diff --git a/crates/completion/src/completions/unqualified_path.rs b/crates/completion/src/completions/unqualified_path.rs index 896f167ff..2da21b5c2 100644 --- a/crates/completion/src/completions/unqualified_path.rs +++ b/crates/completion/src/completions/unqualified_path.rs | |||
@@ -192,12 +192,14 @@ mod tests { | |||
192 | use test_utils::mark; | 192 | use test_utils::mark; |
193 | 193 | ||
194 | use crate::{ | 194 | use crate::{ |
195 | test_utils::{check_edit, check_edit_with_config, completion_list_with_config}, | 195 | test_utils::{ |
196 | check_edit, check_edit_with_config, completion_list_with_config, TEST_CONFIG, | ||
197 | }, | ||
196 | CompletionConfig, CompletionKind, | 198 | CompletionConfig, CompletionKind, |
197 | }; | 199 | }; |
198 | 200 | ||
199 | fn check(ra_fixture: &str, expect: Expect) { | 201 | fn check(ra_fixture: &str, expect: Expect) { |
200 | check_with_config(CompletionConfig::default(), ra_fixture, expect); | 202 | check_with_config(TEST_CONFIG, ra_fixture, expect); |
201 | } | 203 | } |
202 | 204 | ||
203 | fn check_with_config(config: CompletionConfig, ra_fixture: &str, expect: Expect) { | 205 | fn check_with_config(config: CompletionConfig, ra_fixture: &str, expect: Expect) { |
@@ -205,10 +207,6 @@ mod tests { | |||
205 | expect.assert_eq(&actual) | 207 | expect.assert_eq(&actual) |
206 | } | 208 | } |
207 | 209 | ||
208 | fn fuzzy_completion_config() -> CompletionConfig { | ||
209 | CompletionConfig::default() | ||
210 | } | ||
211 | |||
212 | #[test] | 210 | #[test] |
213 | fn self_fulfilling_completion() { | 211 | fn self_fulfilling_completion() { |
214 | mark::check!(self_fulfilling_completion); | 212 | mark::check!(self_fulfilling_completion); |
@@ -832,7 +830,7 @@ impl My<|> | |||
832 | #[test] | 830 | #[test] |
833 | fn function_fuzzy_completion() { | 831 | fn function_fuzzy_completion() { |
834 | check_edit_with_config( | 832 | check_edit_with_config( |
835 | fuzzy_completion_config(), | 833 | TEST_CONFIG, |
836 | "stdin", | 834 | "stdin", |
837 | r#" | 835 | r#" |
838 | //- /lib.rs crate:dep | 836 | //- /lib.rs crate:dep |
@@ -858,7 +856,7 @@ fn main() { | |||
858 | #[test] | 856 | #[test] |
859 | fn macro_fuzzy_completion() { | 857 | fn macro_fuzzy_completion() { |
860 | check_edit_with_config( | 858 | check_edit_with_config( |
861 | fuzzy_completion_config(), | 859 | TEST_CONFIG, |
862 | "macro_with_curlies!", | 860 | "macro_with_curlies!", |
863 | r#" | 861 | r#" |
864 | //- /lib.rs crate:dep | 862 | //- /lib.rs crate:dep |
@@ -886,7 +884,7 @@ fn main() { | |||
886 | #[test] | 884 | #[test] |
887 | fn struct_fuzzy_completion() { | 885 | fn struct_fuzzy_completion() { |
888 | check_edit_with_config( | 886 | check_edit_with_config( |
889 | fuzzy_completion_config(), | 887 | TEST_CONFIG, |
890 | "ThirdStruct", | 888 | "ThirdStruct", |
891 | r#" | 889 | r#" |
892 | //- /lib.rs crate:dep | 890 | //- /lib.rs crate:dep |
@@ -917,7 +915,7 @@ fn main() { | |||
917 | fn fuzzy_completions_come_in_specific_order() { | 915 | fn fuzzy_completions_come_in_specific_order() { |
918 | mark::check!(certain_fuzzy_order_test); | 916 | mark::check!(certain_fuzzy_order_test); |
919 | check_with_config( | 917 | check_with_config( |
920 | fuzzy_completion_config(), | 918 | TEST_CONFIG, |
921 | r#" | 919 | r#" |
922 | //- /lib.rs crate:dep | 920 | //- /lib.rs crate:dep |
923 | pub struct FirstStruct; | 921 | pub struct FirstStruct; |