Allow to configure the merge behavior

This commit is contained in:
Kirill Bulatov 2020-11-10 23:40:07 +02:00
parent 1e458efe62
commit 0e050fc3eb
2 changed files with 6 additions and 5 deletions

View File

@ -1,6 +1,6 @@
//! TODO kb move this into the complete_unqualified_path when starts to work properly //! 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 either::Either;
use hir::{db::HirDatabase, MacroDef, ModuleDef, Query}; use hir::{db::HirDatabase, MacroDef, ModuleDef, Query};
use itertools::Itertools; 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); builder.replace(anchor.syntax().text_range(), correct_qualifier);
// TODO kb: assists already have the merge behaviour setting, need to unite both let rewriter = insert_use(&import_scope, mod_path_to_ast(&mod_path), ctx.config.merge);
// 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 old_ast = rewriter.rewrite_root()?; let old_ast = rewriter.rewrite_root()?;
algo::diff(&old_ast, &rewriter.rewrite(&old_ast)).into_text_edit(&mut builder); algo::diff(&old_ast, &rewriter.rewrite(&old_ast)).into_text_edit(&mut builder);

View File

@ -4,12 +4,15 @@
//! module, and we use to statically check that we only produce snippet //! module, and we use to statically check that we only produce snippet
//! completions if we are allowed to. //! completions if we are allowed to.
use assists::utils::MergeBehaviour;
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub struct CompletionConfig { pub struct CompletionConfig {
pub enable_postfix_completions: bool, pub enable_postfix_completions: bool,
pub add_call_parenthesis: bool, pub add_call_parenthesis: bool,
pub add_call_argument_snippets: bool, pub add_call_argument_snippets: bool,
pub snippet_cap: Option<SnippetCap>, pub snippet_cap: Option<SnippetCap>,
pub merge: Option<MergeBehaviour>,
} }
impl CompletionConfig { impl CompletionConfig {
@ -30,6 +33,7 @@ fn default() -> Self {
add_call_parenthesis: true, add_call_parenthesis: true,
add_call_argument_snippets: true, add_call_argument_snippets: true,
snippet_cap: Some(SnippetCap { _private: () }), snippet_cap: Some(SnippetCap { _private: () }),
merge: Some(MergeBehaviour::Full),
} }
} }
} }