From adc4c6b9d7fd91827c4cf383a1e95dc7e27138e0 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sat, 12 Sep 2020 11:55:01 +0200 Subject: Make MergeBehaviour configurable --- crates/assists/src/handlers/auto_import.rs | 7 ++----- crates/assists/src/handlers/extract_struct_from_enum_variant.rs | 6 ++---- crates/assists/src/handlers/replace_qualified_name_with_use.rs | 4 ++-- 3 files changed, 6 insertions(+), 11 deletions(-) (limited to 'crates/assists/src/handlers') diff --git a/crates/assists/src/handlers/auto_import.rs b/crates/assists/src/handlers/auto_import.rs index 66e819154..b5eb2c722 100644 --- a/crates/assists/src/handlers/auto_import.rs +++ b/crates/assists/src/handlers/auto_import.rs @@ -14,10 +14,7 @@ use syntax::{ SyntaxNode, }; -use crate::{ - utils::{insert_use, MergeBehaviour}, - AssistContext, AssistId, AssistKind, Assists, GroupLabel, -}; +use crate::{utils::insert_use, AssistContext, AssistId, AssistKind, Assists, GroupLabel}; // Assist: auto_import // @@ -60,7 +57,7 @@ pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()> let new_syntax = insert_use( &scope, make::path_from_text(&import.to_string()), - Some(MergeBehaviour::Full), + ctx.config.insert_use.merge, ); builder.replace(syntax.text_range(), new_syntax.to_string()) }, diff --git a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs index 80c62d8bb..3ea50f375 100644 --- a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs +++ b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs @@ -10,9 +10,7 @@ use syntax::{ }; use crate::{ - assist_context::AssistBuilder, - utils::{insert_use, MergeBehaviour}, - AssistContext, AssistId, AssistKind, Assists, + assist_context::AssistBuilder, utils::insert_use, AssistContext, AssistId, AssistKind, Assists, }; use ast::make; use insert_use::ImportScope; @@ -117,7 +115,7 @@ fn insert_import( let new_syntax = insert_use( &scope, make::path_from_text(&mod_path.to_string()), - Some(MergeBehaviour::Full), + ctx.config.insert_use.merge, ); // FIXME: this will currently panic as multiple imports will have overlapping text ranges builder.replace(syntax.text_range(), new_syntax.to_string()) diff --git a/crates/assists/src/handlers/replace_qualified_name_with_use.rs b/crates/assists/src/handlers/replace_qualified_name_with_use.rs index 85c70d16b..e48407fcc 100644 --- a/crates/assists/src/handlers/replace_qualified_name_with_use.rs +++ b/crates/assists/src/handlers/replace_qualified_name_with_use.rs @@ -2,7 +2,7 @@ use syntax::{algo::SyntaxRewriter, ast, match_ast, AstNode, SyntaxNode, TextRang use test_utils::mark; use crate::{ - utils::{insert_use, ImportScope, MergeBehaviour}, + utils::{insert_use, ImportScope}, AssistContext, AssistId, AssistKind, Assists, }; use ast::make; @@ -60,7 +60,7 @@ pub(crate) fn replace_qualified_name_with_use( let new_syntax = insert_use( import_scope, make::path_from_text(path_to_import), - Some(MergeBehaviour::Full), + ctx.config.insert_use.merge, ); builder.replace(syntax.text_range(), new_syntax.to_string()) } -- cgit v1.2.3