]> git.lizzy.rs Git - rust.git/commitdiff
Allow to configure the merge behavior
authorKirill Bulatov <mail4score@gmail.com>
Tue, 10 Nov 2020 21:40:07 +0000 (23:40 +0200)
committerKirill Bulatov <mail4score@gmail.com>
Mon, 16 Nov 2020 19:19:06 +0000 (21:19 +0200)
crates/completion/src/completions/complete_magic.rs
crates/completion/src/config.rs

index 4cf21e19df0fff7dd1f01ebf80258b4cd58ff578..58509fc5babf66758e639ce110afde5c5621150d 100644 (file)
@@ -1,6 +1,6 @@
 //! TODO kb move this into the complete_unqualified_path when starts to work properly
 
-use assists::utils::{insert_use, mod_path_to_ast, ImportScope, MergeBehaviour};
+use assists::utils::{insert_use, mod_path_to_ast, ImportScope};
 use either::Either;
 use hir::{db::HirDatabase, MacroDef, ModuleDef, Query};
 use itertools::Itertools;
@@ -48,10 +48,7 @@ pub(crate) fn complete_magic(acc: &mut Completions, ctx: &CompletionContext) ->
             );
             builder.replace(anchor.syntax().text_range(), correct_qualifier);
 
-            // TODO kb: assists already have the merge behaviour setting, need to unite both
-            // also consider a settings toggle for this particular feature?
-            let rewriter =
-                insert_use(&import_scope, mod_path_to_ast(&mod_path), Some(MergeBehaviour::Full));
+            let rewriter = insert_use(&import_scope, mod_path_to_ast(&mod_path), ctx.config.merge);
             let old_ast = rewriter.rewrite_root()?;
             algo::diff(&old_ast, &rewriter.rewrite(&old_ast)).into_text_edit(&mut builder);
 
index 71b49ace8bfb0e38a746ff34866d9f3a3cfb46dc..82874ff256a610cb37a4388bc69ea9a40fea70e7 100644 (file)
@@ -4,12 +4,15 @@
 //! module, and we use to statically check that we only produce snippet
 //! completions if we are allowed to.
 
+use assists::utils::MergeBehaviour;
+
 #[derive(Clone, Debug, PartialEq, Eq)]
 pub struct CompletionConfig {
     pub enable_postfix_completions: bool,
     pub add_call_parenthesis: bool,
     pub add_call_argument_snippets: bool,
     pub snippet_cap: Option<SnippetCap>,
+    pub merge: Option<MergeBehaviour>,
 }
 
 impl CompletionConfig {
@@ -30,6 +33,7 @@ fn default() -> Self {
             add_call_parenthesis: true,
             add_call_argument_snippets: true,
             snippet_cap: Some(SnippetCap { _private: () }),
+            merge: Some(MergeBehaviour::Full),
         }
     }
 }