From ba02a55330d2ec9a0ea2c5cd457b82782ae299e9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 28 Aug 2018 22:58:02 +0300 Subject: simplify --- crates/libeditor/src/code_actions.rs | 40 +++++------------------------------- 1 file changed, 5 insertions(+), 35 deletions(-) (limited to 'crates/libeditor') diff --git a/crates/libeditor/src/code_actions.rs b/crates/libeditor/src/code_actions.rs index cef3a12f9..684b8243a 100644 --- a/crates/libeditor/src/code_actions.rs +++ b/crates/libeditor/src/code_actions.rs @@ -1,7 +1,3 @@ -use std::{ - fmt::{self, Write}, -}; - use join_to_string::join; use libsyntax2::{ @@ -78,17 +74,15 @@ pub fn add_impl<'a>(file: &'a File, offset: TextUnit) -> Option let mut buf = String::new(); buf.push_str("\n\nimpl"); if let Some(type_params) = type_params { - buf.push_display(&type_params.syntax().text()); + type_params.syntax().text() + .push_to(&mut buf); } buf.push_str(" "); buf.push_str(name.text().as_str()); if let Some(type_params) = type_params { - comma_list( - &mut buf, "<", ">", - type_params.type_params() - .filter_map(|it| it.name()) - .map(|it| it.text()) - ); + join(type_params.type_params().filter_map(|it| it.name()).map(|it| it.text())) + .surround_with("<", ">") + .to_buf(&mut buf); } buf.push_str(" {\n"); let offset = start_offset + TextUnit::of_str(&buf); @@ -107,30 +101,6 @@ fn non_trivia_sibling(node: SyntaxNodeRef, direction: Direction) -> Option) { - buf.push_str(bra); - let mut first = true; - for item in items { - if !first { - buf.push_str(", "); - } - first = false; - write!(buf, "{}", item).unwrap(); - } - buf.push_str(ket); -} - -trait PushDisplay { - fn push_display(&mut self, item: &T); -} - -impl PushDisplay for String { - fn push_display(&mut self, item: &T) { - use std::fmt::Write; - write!(self, "{}", item).unwrap() - } -} - #[cfg(test)] mod tests { use super::*; -- cgit v1.2.3