From 1c359ab634edb81b51e3c7eadfb83d46c926e890 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 12 Aug 2020 15:04:06 +0200 Subject: Replace SepBy with Itertools --- crates/ra_assists/src/handlers/add_custom_impl.rs | 4 ++-- crates/ra_assists/src/handlers/generate_impl.rs | 5 +++-- crates/ra_assists/src/handlers/generate_new.rs | 9 +++++---- 3 files changed, 10 insertions(+), 8 deletions(-) (limited to 'crates/ra_assists') diff --git a/crates/ra_assists/src/handlers/add_custom_impl.rs b/crates/ra_assists/src/handlers/add_custom_impl.rs index b67438b6b..ebdf00e67 100644 --- a/crates/ra_assists/src/handlers/add_custom_impl.rs +++ b/crates/ra_assists/src/handlers/add_custom_impl.rs @@ -1,10 +1,10 @@ +use itertools::Itertools; use ra_syntax::{ ast::{self, AstNode}, Direction, SmolStr, SyntaxKind::{IDENT, WHITESPACE}, TextRange, TextSize, }; -use stdx::SepBy; use crate::{ assist_context::{AssistContext, Assists}, @@ -61,9 +61,9 @@ pub(crate) fn add_custom_impl(acc: &mut Assists, ctx: &AssistContext) -> Option< .filter(|t| t != trait_token.text()) .collect::>(); let has_more_derives = !new_attr_input.is_empty(); - let new_attr_input = new_attr_input.iter().sep_by(", ").surround_with("(", ")").to_string(); if has_more_derives { + let new_attr_input = format!("({})", new_attr_input.iter().format(", ")); builder.replace(input.syntax().text_range(), new_attr_input); } else { let attr_range = attr.syntax().text_range(); diff --git a/crates/ra_assists/src/handlers/generate_impl.rs b/crates/ra_assists/src/handlers/generate_impl.rs index d9b87c9c0..7162dc184 100644 --- a/crates/ra_assists/src/handlers/generate_impl.rs +++ b/crates/ra_assists/src/handlers/generate_impl.rs @@ -1,5 +1,6 @@ +use itertools::Itertools; use ra_syntax::ast::{self, AstNode, GenericParamsOwner, NameOwner}; -use stdx::{format_to, SepBy}; +use stdx::format_to; use crate::{AssistContext, AssistId, AssistKind, Assists}; @@ -50,7 +51,7 @@ pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<() .filter_map(|it| it.name()) .map(|it| it.text().clone()); - let generic_params = lifetime_params.chain(type_params).sep_by(", "); + let generic_params = lifetime_params.chain(type_params).format(", "); format_to!(buf, "<{}>", generic_params) } match ctx.config.snippet_cap { diff --git a/crates/ra_assists/src/handlers/generate_new.rs b/crates/ra_assists/src/handlers/generate_new.rs index b84aa24b6..32dfed274 100644 --- a/crates/ra_assists/src/handlers/generate_new.rs +++ b/crates/ra_assists/src/handlers/generate_new.rs @@ -1,9 +1,10 @@ use hir::Adt; +use itertools::Itertools; use ra_syntax::{ ast::{self, AstNode, GenericParamsOwner, NameOwner, StructKind, VisibilityOwner}, T, }; -use stdx::{format_to, SepBy}; +use stdx::format_to; use crate::{AssistContext, AssistId, AssistKind, Assists}; @@ -52,8 +53,8 @@ pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext) -> Option<()> let params = field_list .fields() .filter_map(|f| Some(format!("{}: {}", f.name()?.syntax(), f.ty()?.syntax()))) - .sep_by(", "); - let fields = field_list.fields().filter_map(|f| f.name()).sep_by(", "); + .format(", "); + let fields = field_list.fields().filter_map(|f| f.name()).format(", "); format_to!(buf, " {}fn new({}) -> Self {{ Self {{ {} }} }}", vis, params, fields); @@ -102,7 +103,7 @@ fn generate_impl_text(strukt: &ast::Struct, code: &str) -> String { .map(|it| it.text().clone()); let type_params = type_params.type_params().filter_map(|it| it.name()).map(|it| it.text().clone()); - format_to!(buf, "<{}>", lifetime_params.chain(type_params).sep_by(", ")) + format_to!(buf, "<{}>", lifetime_params.chain(type_params).format(", ")) } format_to!(buf, " {{\n{}\n}}\n", code); -- cgit v1.2.3