Skip to content

Commit a52fa8d

Browse files
Merge pull request #22073 from Albab-Hasan/fix-22071-empty-block-comment-panic
fix: handle empty `/**/` in block_to_line assist
2 parents 26d7ba3 + beacd8a commit a52fa8d

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

crates/ide-assists/src/handlers/convert_comment_block.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,21 @@ fn main() {
381381
);
382382
}
383383

384+
#[test]
385+
fn empty_block_to_line() {
386+
check_assist(
387+
convert_comment_block,
388+
r#"
389+
/**/$0
390+
fn main() {}
391+
"#,
392+
r#"
393+
394+
fn main() {}
395+
"#,
396+
);
397+
}
398+
384399
#[test]
385400
fn end_of_line_block_to_line() {
386401
check_assist_not_applicable(

crates/syntax/src/ast/token_ext.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@ impl ast::Comment {
3232
}
3333

3434
pub fn prefix(&self) -> &'static str {
35-
let &(prefix, _kind) = CommentKind::BY_PREFIX
36-
.iter()
37-
.find(|&(prefix, kind)| self.kind() == *kind && self.text().starts_with(prefix))
38-
.unwrap();
39-
prefix
35+
self.kind().prefix()
4036
}
4137

4238
/// Returns the textual content of a doc comment node as a single string with prefix and suffix

0 commit comments

Comments
 (0)