diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-03-28 11:28:31 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-03-28 11:28:31 +0000 |
commit | c30425dc96895117b644f29b758cee9dac36839b (patch) | |
tree | d3ccef4aa8f681cc9de29f0435ad20e87911a6ba /crates/ra_assists/src/handlers/add_impl.rs | |
parent | a1fea0d34ee8f3436aefd87d4c133a7ff50ffbb0 (diff) | |
parent | 311cbbdad599d51c6f08f7dd72c299f7c0128bb2 (diff) |
Merge #3753
3753: Introduce stdx crate r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_assists/src/handlers/add_impl.rs')
-rw-r--r-- | crates/ra_assists/src/handlers/add_impl.rs | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/crates/ra_assists/src/handlers/add_impl.rs b/crates/ra_assists/src/handlers/add_impl.rs index afae7d385..6622eadb2 100644 --- a/crates/ra_assists/src/handlers/add_impl.rs +++ b/crates/ra_assists/src/handlers/add_impl.rs | |||
@@ -1,9 +1,8 @@ | |||
1 | use format_buf::format; | ||
2 | use join_to_string::join; | ||
3 | use ra_syntax::{ | 1 | use ra_syntax::{ |
4 | ast::{self, AstNode, NameOwner, TypeParamsOwner}, | 2 | ast::{self, AstNode, NameOwner, TypeParamsOwner}, |
5 | TextUnit, | 3 | TextUnit, |
6 | }; | 4 | }; |
5 | use stdx::{format_to, SepBy}; | ||
7 | 6 | ||
8 | use crate::{Assist, AssistCtx, AssistId}; | 7 | use crate::{Assist, AssistCtx, AssistId}; |
9 | 8 | ||
@@ -36,7 +35,7 @@ pub(crate) fn add_impl(ctx: AssistCtx) -> Option<Assist> { | |||
36 | let mut buf = String::new(); | 35 | let mut buf = String::new(); |
37 | buf.push_str("\n\nimpl"); | 36 | buf.push_str("\n\nimpl"); |
38 | if let Some(type_params) = &type_params { | 37 | if let Some(type_params) = &type_params { |
39 | format!(buf, "{}", type_params.syntax()); | 38 | format_to!(buf, "{}", type_params.syntax()); |
40 | } | 39 | } |
41 | buf.push_str(" "); | 40 | buf.push_str(" "); |
42 | buf.push_str(name.text().as_str()); | 41 | buf.push_str(name.text().as_str()); |
@@ -47,7 +46,9 @@ pub(crate) fn add_impl(ctx: AssistCtx) -> Option<Assist> { | |||
47 | .map(|it| it.text().clone()); | 46 | .map(|it| it.text().clone()); |
48 | let type_params = | 47 | let type_params = |
49 | type_params.type_params().filter_map(|it| it.name()).map(|it| it.text().clone()); | 48 | type_params.type_params().filter_map(|it| it.name()).map(|it| it.text().clone()); |
50 | join(lifetime_params.chain(type_params)).surround_with("<", ">").to_buf(&mut buf); | 49 | |
50 | let generic_params = lifetime_params.chain(type_params).sep_by(", "); | ||
51 | format_to!(buf, "<{}>", generic_params) | ||
51 | } | 52 | } |
52 | buf.push_str(" {\n"); | 53 | buf.push_str(" {\n"); |
53 | edit.set_cursor(start_offset + TextUnit::of_str(&buf)); | 54 | edit.set_cursor(start_offset + TextUnit::of_str(&buf)); |