mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 15:15:24 +00:00
Remove smart multiline comment join
This commit is contained in:
parent
92f5ca64ae
commit
6fe77db413
1 changed files with 23 additions and 22 deletions
|
@ -174,27 +174,10 @@ fn remove_newline(
|
||||||
);
|
);
|
||||||
} else if let (Some(_), Some(next)) = (ast::Comment::cast(prev), ast::Comment::cast(next)) {
|
} else if let (Some(_), Some(next)) = (ast::Comment::cast(prev), ast::Comment::cast(next)) {
|
||||||
// Removes: newline (incl. surrounding whitespace), start of the next comment
|
// Removes: newline (incl. surrounding whitespace), start of the next comment
|
||||||
let comment_text = next.text();
|
edit.delete(TextRange::from_to(
|
||||||
if let Some(newline_pos) = comment_text.find('\n') {
|
node.range().start(),
|
||||||
// Special case for multiline comments: join the comment content but
|
next.syntax().range().start() + TextUnit::of_str(next.prefix())
|
||||||
// keep the leading `/*`
|
));
|
||||||
|
|
||||||
let newline_offset = next.syntax().range().start()
|
|
||||||
+ TextUnit::from(newline_pos as u32)
|
|
||||||
+ TextUnit::of_char('\n');
|
|
||||||
|
|
||||||
edit.insert(newline_offset, "/*".to_string());
|
|
||||||
edit.delete(TextRange::from_to(
|
|
||||||
node.range().start(),
|
|
||||||
next.syntax().range().start() + TextUnit::of_str(next.prefix())
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
// Single-line comments
|
|
||||||
edit.delete(TextRange::from_to(
|
|
||||||
node.range().start(),
|
|
||||||
next.syntax().range().start() + TextUnit::of_str(next.prefix())
|
|
||||||
));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Remove newline but add a computed amount of whitespace characters
|
// Remove newline but add a computed amount of whitespace characters
|
||||||
edit.replace(
|
edit.replace(
|
||||||
|
@ -356,7 +339,7 @@ fn foo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_join_lines_multiline_comments() {
|
fn test_join_lines_multiline_comments_1() {
|
||||||
check_join_lines(r"
|
check_join_lines(r"
|
||||||
fn foo() {
|
fn foo() {
|
||||||
// Hello<|>
|
// Hello<|>
|
||||||
|
@ -369,6 +352,24 @@ fn foo() {
|
||||||
");
|
");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_join_lines_multiline_comments_2() {
|
||||||
|
check_join_lines(r"
|
||||||
|
fn foo() {
|
||||||
|
// The<|>
|
||||||
|
/* quick
|
||||||
|
brown
|
||||||
|
fox! */
|
||||||
|
}
|
||||||
|
", r"
|
||||||
|
fn foo() {
|
||||||
|
// The<|> quick
|
||||||
|
brown
|
||||||
|
fox! */
|
||||||
|
}
|
||||||
|
");
|
||||||
|
}
|
||||||
|
|
||||||
fn check_join_lines_sel(before: &str, after: &str) {
|
fn check_join_lines_sel(before: &str, after: &str) {
|
||||||
let (sel, before) = extract_range(before);
|
let (sel, before) = extract_range(before);
|
||||||
let file = File::parse(&before);
|
let file = File::parse(&before);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue