diff options
Diffstat (limited to 'crates/assists/src/utils.rs')
-rw-r--r-- | crates/assists/src/utils.rs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/crates/assists/src/utils.rs b/crates/assists/src/utils.rs index 5dd32aef1..98c4462bb 100644 --- a/crates/assists/src/utils.rs +++ b/crates/assists/src/utils.rs | |||
@@ -367,13 +367,31 @@ 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\n"); |
383 | adt.attrs() | ||
384 | .filter(|attr| attr.as_simple_call().map(|(name, _arg)| name == "cfg").unwrap_or(false)) | ||
385 | .for_each(|attr| buf.push_str(format!("{}\n", attr.to_string()).as_str())); | ||
386 | buf.push_str("impl"); | ||
373 | if let Some(type_params) = &type_params { | 387 | if let Some(type_params) = &type_params { |
374 | format_to!(buf, "{}", type_params.syntax()); | 388 | format_to!(buf, "{}", type_params.syntax()); |
375 | } | 389 | } |
376 | buf.push(' '); | 390 | buf.push(' '); |
391 | if let Some(trait_text) = trait_text { | ||
392 | buf.push_str(trait_text); | ||
393 | buf.push_str(" for "); | ||
394 | } | ||
377 | buf.push_str(adt.name().unwrap().text()); | 395 | buf.push_str(adt.name().unwrap().text()); |
378 | if let Some(type_params) = type_params { | 396 | if let Some(type_params) = type_params { |
379 | let lifetime_params = type_params | 397 | let lifetime_params = type_params |