@@ -25,9 +25,7 @@ pub(crate) fn convert_comment_block(acc: &mut Assists, ctx: &AssistContext<'_>)
25
25
let comment = ctx. find_token_at_offset :: < ast:: Comment > ( ) ?;
26
26
// Only allow comments which are alone on their line
27
27
if let Some ( prev) = comment. syntax ( ) . prev_token ( ) {
28
- if Whitespace :: cast ( prev) . filter ( |w| w. text ( ) . contains ( '\n' ) ) . is_none ( ) {
29
- return None ;
30
- }
28
+ Whitespace :: cast ( prev) . filter ( |w| w. text ( ) . contains ( '\n' ) ) ?;
31
29
}
32
30
33
31
match comment. kind ( ) . shape {
@@ -78,7 +76,7 @@ fn line_to_block(acc: &mut Assists, comment: ast::Comment) -> Option<()> {
78
76
// Establish the target of our edit based on the comments we found
79
77
let target = TextRange :: new (
80
78
comments[ 0 ] . syntax ( ) . text_range ( ) . start ( ) ,
81
- comments. last ( ) . unwrap ( ) . syntax ( ) . text_range ( ) . end ( ) ,
79
+ comments. last ( ) ? . syntax ( ) . text_range ( ) . end ( ) ,
82
80
) ;
83
81
84
82
acc. add (
@@ -91,8 +89,12 @@ fn line_to_block(acc: &mut Assists, comment: ast::Comment) -> Option<()> {
91
89
// contents of each line comment when they're put into the block comment.
92
90
let indentation = IndentLevel :: from_token ( comment. syntax ( ) ) ;
93
91
94
- let block_comment_body =
95
- comments. into_iter ( ) . map ( |c| line_comment_text ( indentation, c) ) . join ( "\n " ) ;
92
+ let block_comment_body = comments
93
+ . into_iter ( )
94
+ . map ( |c| line_comment_text ( indentation, c) )
95
+ . collect :: < Vec < String > > ( )
96
+ . into_iter ( )
97
+ . join ( "\n " ) ;
96
98
97
99
let block_prefix =
98
100
CommentKind { shape : CommentShape :: Block , ..comment. kind ( ) } . prefix ( ) ;
@@ -160,7 +162,8 @@ pub(crate) fn relevant_line_comments(comment: &ast::Comment) -> Vec<Comment> {
160
162
//
161
163
// But since such comments aren't idiomatic we're okay with this.
162
164
pub ( crate ) fn line_comment_text ( indentation : IndentLevel , comm : ast:: Comment ) -> String {
163
- let contents_without_prefix = comm. text ( ) . strip_prefix ( comm. prefix ( ) ) . unwrap ( ) ;
165
+ let text = comm. text ( ) ;
166
+ let contents_without_prefix = text. strip_prefix ( comm. prefix ( ) ) . unwrap_or ( text) ;
164
167
let contents = contents_without_prefix. strip_prefix ( ' ' ) . unwrap_or ( contents_without_prefix) ;
165
168
166
169
// Don't add the indentation if the line is empty
0 commit comments