mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 06:03:58 +00:00
Fix join lines when two rules match
This commit is contained in:
parent
305d921982
commit
adfed5c689
1 changed files with 46 additions and 23 deletions
|
@ -60,29 +60,6 @@ fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextU
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special case that turns something like:
|
|
||||||
//
|
|
||||||
// ```
|
|
||||||
// my_function({<|>
|
|
||||||
// <some-expr>
|
|
||||||
// })
|
|
||||||
// ```
|
|
||||||
//
|
|
||||||
// into `my_function(<some-expr>)`
|
|
||||||
if join_single_expr_block(edit, token).is_some() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// ditto for
|
|
||||||
//
|
|
||||||
// ```
|
|
||||||
// use foo::{<|>
|
|
||||||
// bar
|
|
||||||
// };
|
|
||||||
// ```
|
|
||||||
if join_single_use_tree(edit, token).is_some() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The node is between two other nodes
|
// The node is between two other nodes
|
||||||
let prev = token.prev_sibling_or_token().unwrap();
|
let prev = token.prev_sibling_or_token().unwrap();
|
||||||
let next = token.next_sibling_or_token().unwrap();
|
let next = token.next_sibling_or_token().unwrap();
|
||||||
|
@ -110,6 +87,29 @@ fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextU
|
||||||
next.syntax().text_range().start() + TextUnit::of_str(next.prefix()),
|
next.syntax().text_range().start() + TextUnit::of_str(next.prefix()),
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
|
// Special case that turns something like:
|
||||||
|
//
|
||||||
|
// ```
|
||||||
|
// my_function({<|>
|
||||||
|
// <some-expr>
|
||||||
|
// })
|
||||||
|
// ```
|
||||||
|
//
|
||||||
|
// into `my_function(<some-expr>)`
|
||||||
|
if join_single_expr_block(edit, token).is_some() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// ditto for
|
||||||
|
//
|
||||||
|
// ```
|
||||||
|
// use foo::{<|>
|
||||||
|
// bar
|
||||||
|
// };
|
||||||
|
// ```
|
||||||
|
if join_single_use_tree(edit, token).is_some() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Remove newline but add a computed amount of whitespace characters
|
// Remove newline but add a computed amount of whitespace characters
|
||||||
edit.replace(token.text_range(), compute_ws(prev.kind(), next.kind()).to_string());
|
edit.replace(token.text_range(), compute_ws(prev.kind(), next.kind()).to_string());
|
||||||
}
|
}
|
||||||
|
@ -608,4 +608,27 @@ pub fn handle_find_matching_brace() {
|
||||||
}",
|
}",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_join_lines_commented_block() {
|
||||||
|
check_join_lines(
|
||||||
|
r"
|
||||||
|
fn main() {
|
||||||
|
let _ = {
|
||||||
|
// <|>foo
|
||||||
|
// bar
|
||||||
|
92
|
||||||
|
};
|
||||||
|
}
|
||||||
|
",
|
||||||
|
r"
|
||||||
|
fn main() {
|
||||||
|
let _ = {
|
||||||
|
// <|>foo bar
|
||||||
|
92
|
||||||
|
};
|
||||||
|
}
|
||||||
|
",
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue