]> git.lizzy.rs Git - rust.git/blobdiff - crates/ide_assists/src/handlers/convert_comment_block.rs
Merge #11481
[rust.git] / crates / ide_assists / src / handlers / convert_comment_block.rs
index d202a85f958883845b0ee53f593fcf006dfaab77..3261f5652592e0821c3e6d724761eba24cb81233 100644 (file)
@@ -6,21 +6,21 @@
 
 use crate::{AssistContext, AssistId, AssistKind, Assists};
 
-/// Assist: line_to_block
-///
-/// Converts comments between block and single-line form
-///
-/// ```
-///    // Multi-line
-///    // comment
-/// ```
-/// ->
-/// ```
-///   /**
-///   Multi-line
-///   comment
-///   */
-/// ```
+// Assist: line_to_block
+//
+// Converts comments between block and single-line form.
+//
+// ```
+//    // Multi-line$0
+//    // comment
+// ```
+// ->
+// ```
+//   /*
+//   Multi-line
+//   comment
+//   */
+// ```
 pub(crate) fn convert_comment_block(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
     let comment = ctx.find_token_at_offset::<ast::Comment>()?;
     // Only allow comments which are alone on their line
@@ -88,7 +88,7 @@ fn line_to_block(acc: &mut Assists, comment: ast::Comment) -> Option<()> {
             // We pick a single indentation level for the whole block comment based on the
             // comment where the assist was invoked. This will be prepended to the
             // contents of each line comment when they're put into the block comment.
-            let indentation = IndentLevel::from_token(&comment.syntax());
+            let indentation = IndentLevel::from_token(comment.syntax());
 
             let block_comment_body =
                 comments.into_iter().map(|c| line_comment_text(indentation, c)).join("\n");
@@ -96,8 +96,7 @@ fn line_to_block(acc: &mut Assists, comment: ast::Comment) -> Option<()> {
             let block_prefix =
                 CommentKind { shape: CommentShape::Block, ..comment.kind() }.prefix();
 
-            let output =
-                format!("{}\n{}\n{}*/", block_prefix, block_comment_body, indentation.to_string());
+            let output = format!("{}\n{}\n{}*/", block_prefix, block_comment_body, indentation);
 
             edit.replace(target, output)
         },
@@ -167,7 +166,7 @@ fn line_comment_text(indentation: IndentLevel, comm: ast::Comment) -> String {
     if contents.is_empty() {
         contents.to_owned()
     } else {
-        indentation.to_string() + &contents
+        indentation.to_string() + contents
     }
 }