diff options
author | Kirill Bulatov <[email protected]> | 2020-11-10 21:40:07 +0000 |
---|---|---|
committer | Kirill Bulatov <[email protected]> | 2020-11-16 19:19:06 +0000 |
commit | 0e050fc3eba251f3debf964c7779c522e5639cd8 (patch) | |
tree | a56bfe84df95870072bd3ad9e6747c8ed813d64a /crates/completion | |
parent | 1e458efe628215dfc07943f8dd39f66ac059d3de (diff) |
Allow to configure the merge behavior
Diffstat (limited to 'crates/completion')
-rw-r--r-- | crates/completion/src/completions/complete_magic.rs | 7 | ||||
-rw-r--r-- | crates/completion/src/config.rs | 4 |
2 files changed, 6 insertions, 5 deletions
diff --git a/crates/completion/src/completions/complete_magic.rs b/crates/completion/src/completions/complete_magic.rs index 4cf21e19d..58509fc5b 100644 --- a/crates/completion/src/completions/complete_magic.rs +++ b/crates/completion/src/completions/complete_magic.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | //! TODO kb move this into the complete_unqualified_path when starts to work properly | 1 | //! TODO kb move this into the complete_unqualified_path when starts to work properly |
2 | 2 | ||
3 | use assists::utils::{insert_use, mod_path_to_ast, ImportScope, MergeBehaviour}; | 3 | use assists::utils::{insert_use, mod_path_to_ast, ImportScope}; |
4 | use either::Either; | 4 | use either::Either; |
5 | use hir::{db::HirDatabase, MacroDef, ModuleDef, Query}; | 5 | use hir::{db::HirDatabase, MacroDef, ModuleDef, Query}; |
6 | use itertools::Itertools; | 6 | use itertools::Itertools; |
@@ -48,10 +48,7 @@ pub(crate) fn complete_magic(acc: &mut Completions, ctx: &CompletionContext) -> | |||
48 | ); | 48 | ); |
49 | builder.replace(anchor.syntax().text_range(), correct_qualifier); | 49 | builder.replace(anchor.syntax().text_range(), correct_qualifier); |
50 | 50 | ||
51 | // TODO kb: assists already have the merge behaviour setting, need to unite both | 51 | let rewriter = insert_use(&import_scope, mod_path_to_ast(&mod_path), ctx.config.merge); |
52 | // also consider a settings toggle for this particular feature? | ||
53 | let rewriter = | ||
54 | insert_use(&import_scope, mod_path_to_ast(&mod_path), Some(MergeBehaviour::Full)); | ||
55 | let old_ast = rewriter.rewrite_root()?; | 52 | let old_ast = rewriter.rewrite_root()?; |
56 | algo::diff(&old_ast, &rewriter.rewrite(&old_ast)).into_text_edit(&mut builder); | 53 | algo::diff(&old_ast, &rewriter.rewrite(&old_ast)).into_text_edit(&mut builder); |
57 | 54 | ||
diff --git a/crates/completion/src/config.rs b/crates/completion/src/config.rs index 71b49ace8..82874ff25 100644 --- a/crates/completion/src/config.rs +++ b/crates/completion/src/config.rs | |||
@@ -4,12 +4,15 @@ | |||
4 | //! module, and we use to statically check that we only produce snippet | 4 | //! module, and we use to statically check that we only produce snippet |
5 | //! completions if we are allowed to. | 5 | //! completions if we are allowed to. |
6 | 6 | ||
7 | use assists::utils::MergeBehaviour; | ||
8 | |||
7 | #[derive(Clone, Debug, PartialEq, Eq)] | 9 | #[derive(Clone, Debug, PartialEq, Eq)] |
8 | pub struct CompletionConfig { | 10 | pub struct CompletionConfig { |
9 | pub enable_postfix_completions: bool, | 11 | pub enable_postfix_completions: bool, |
10 | pub add_call_parenthesis: bool, | 12 | pub add_call_parenthesis: bool, |
11 | pub add_call_argument_snippets: bool, | 13 | pub add_call_argument_snippets: bool, |
12 | pub snippet_cap: Option<SnippetCap>, | 14 | pub snippet_cap: Option<SnippetCap>, |
15 | pub merge: Option<MergeBehaviour>, | ||
13 | } | 16 | } |
14 | 17 | ||
15 | impl CompletionConfig { | 18 | impl CompletionConfig { |
@@ -30,6 +33,7 @@ impl Default for CompletionConfig { | |||
30 | add_call_parenthesis: true, | 33 | add_call_parenthesis: true, |
31 | add_call_argument_snippets: true, | 34 | add_call_argument_snippets: true, |
32 | snippet_cap: Some(SnippetCap { _private: () }), | 35 | snippet_cap: Some(SnippetCap { _private: () }), |
36 | merge: Some(MergeBehaviour::Full), | ||
33 | } | 37 | } |
34 | } | 38 | } |
35 | } | 39 | } |