From b764c38436fcb9426eb7da3be4f5fbcd63b316f5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 28 Mar 2020 11:01:25 +0100 Subject: Start stdx This crate will hold everything to small to be worth publishing --- crates/ra_assists/src/handlers/add_custom_impl.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'crates/ra_assists/src/handlers/add_custom_impl.rs') diff --git a/crates/ra_assists/src/handlers/add_custom_impl.rs b/crates/ra_assists/src/handlers/add_custom_impl.rs index dd2bed25a..15f9b216b 100644 --- a/crates/ra_assists/src/handlers/add_custom_impl.rs +++ b/crates/ra_assists/src/handlers/add_custom_impl.rs @@ -1,17 +1,13 @@ -//! FIXME: write short doc here - -use join_to_string::join; use ra_syntax::{ ast::{self, AstNode}, Direction, SmolStr, SyntaxKind::{IDENT, WHITESPACE}, TextRange, TextUnit, }; +use stdx::SepBy; use crate::{Assist, AssistCtx, AssistId}; -const DERIVE_TRAIT: &str = "derive"; - // Assist: add_custom_impl // // Adds impl block for derived trait. @@ -38,7 +34,7 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option { .descendants_with_tokens() .filter(|t| t.kind() == IDENT) .find_map(|i| i.into_token()) - .filter(|t| *t.text() == DERIVE_TRAIT)? + .filter(|t| *t.text() == "derive")? .text() .clone(); @@ -63,8 +59,7 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option { .filter(|t| t != trait_token.text()) .collect::>(); let has_more_derives = !new_attr_input.is_empty(); - let new_attr_input = - join(new_attr_input.iter()).separator(", ").surround_with("(", ")").to_string(); + let new_attr_input = new_attr_input.iter().sep_by(", ").surround_with("(", ")").to_string(); let new_attr_input_len = new_attr_input.len(); let mut buf = String::new(); @@ -100,9 +95,10 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option { #[cfg(test)] mod tests { - use super::*; use crate::helpers::{check_assist, check_assist_not_applicable}; + use super::*; + #[test] fn add_custom_impl_for_unique_input() { check_assist( -- cgit v1.2.3