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
// 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");
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)
},
if contents.is_empty() {
contents.to_owned()
} else {
- indentation.to_string() + &contents
+ indentation.to_string() + contents
}
}