diff options
Diffstat (limited to 'crates/assists/src/utils.rs')
-rw-r--r-- | crates/assists/src/utils.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/crates/assists/src/utils.rs b/crates/assists/src/utils.rs index 5dd32aef1..69c107f63 100644 --- a/crates/assists/src/utils.rs +++ b/crates/assists/src/utils.rs | |||
@@ -367,6 +367,16 @@ pub(crate) fn find_impl_block_end(impl_def: ast::Impl, buf: &mut String) -> Opti | |||
367 | // Generates the surrounding `impl Type { <code> }` including type and lifetime | 367 | // Generates the surrounding `impl Type { <code> }` including type and lifetime |
368 | // parameters | 368 | // parameters |
369 | pub(crate) fn generate_impl_text(adt: &ast::Adt, code: &str) -> String { | 369 | pub(crate) fn generate_impl_text(adt: &ast::Adt, code: &str) -> String { |
370 | generate_impl_text_inner(adt, None, code) | ||
371 | } | ||
372 | |||
373 | // Generates the surrounding `impl <trait> for Type { <code> }` including type | ||
374 | // and lifetime parameters | ||
375 | pub(crate) fn generate_trait_impl_text(adt: &ast::Adt, trait_text: &str, code: &str) -> String { | ||
376 | generate_impl_text_inner(adt, Some(trait_text), code) | ||
377 | } | ||
378 | |||
379 | fn generate_impl_text_inner(adt: &ast::Adt, trait_text: Option<&str>, code: &str) -> String { | ||
370 | let type_params = adt.generic_param_list(); | 380 | let type_params = adt.generic_param_list(); |
371 | let mut buf = String::with_capacity(code.len()); | 381 | let mut buf = String::with_capacity(code.len()); |
372 | buf.push_str("\n\nimpl"); | 382 | buf.push_str("\n\nimpl"); |
@@ -374,6 +384,10 @@ pub(crate) fn generate_impl_text(adt: &ast::Adt, code: &str) -> String { | |||
374 | format_to!(buf, "{}", type_params.syntax()); | 384 | format_to!(buf, "{}", type_params.syntax()); |
375 | } | 385 | } |
376 | buf.push(' '); | 386 | buf.push(' '); |
387 | if let Some(trait_text) = trait_text { | ||
388 | buf.push_str(trait_text); | ||
389 | buf.push_str(" for "); | ||
390 | } | ||
377 | buf.push_str(adt.name().unwrap().text()); | 391 | buf.push_str(adt.name().unwrap().text()); |
378 | if let Some(type_params) = type_params { | 392 | if let Some(type_params) = type_params { |
379 | let lifetime_params = type_params | 393 | let lifetime_params = type_params |