From 0e050fc3eba251f3debf964c7779c522e5639cd8 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Tue, 10 Nov 2020 23:40:07 +0200 Subject: Allow to configure the merge behavior --- crates/completion/src/completions/complete_magic.rs | 7 ++----- 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 @@ //! 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); 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 @@ //! 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, + pub merge: Option, } impl CompletionConfig { @@ -30,6 +33,7 @@ impl Default for CompletionConfig { add_call_parenthesis: true, add_call_argument_snippets: true, snippet_cap: Some(SnippetCap { _private: () }), + merge: Some(MergeBehaviour::Full), } } } -- cgit v1.2.3