mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
don't tear body
This commit is contained in:
parent
e72ed9230a
commit
51c50dd5ac
1 changed files with 26 additions and 2 deletions
|
@ -482,8 +482,11 @@ impl FunctionBody {
|
||||||
let full_body = parent.syntax().children_with_tokens();
|
let full_body = parent.syntax().children_with_tokens();
|
||||||
|
|
||||||
let mut text_range = full_body
|
let mut text_range = full_body
|
||||||
.map(|stmt| stmt.text_range())
|
.filter(|it| {
|
||||||
.filter(|&stmt| selected.intersect(stmt).filter(|it| !it.is_empty()).is_some())
|
matches!(it.kind().is_punct() || it.kind() == SyntaxKind::WHITESPACE, false)
|
||||||
|
})
|
||||||
|
.map(|element| element.text_range())
|
||||||
|
.filter(|&range| selected.intersect(range).filter(|it| !it.is_empty()).is_some())
|
||||||
.reduce(|acc, stmt| acc.cover(stmt));
|
.reduce(|acc, stmt| acc.cover(stmt));
|
||||||
|
|
||||||
if let Some(tail_range) = parent
|
if let Some(tail_range) = parent
|
||||||
|
@ -4126,6 +4129,27 @@ fn $0fun_name() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn extract_does_not_tear_body_apart() {
|
||||||
|
check_assist(
|
||||||
|
extract_function,
|
||||||
|
r#"
|
||||||
|
fn foo() {
|
||||||
|
$0foo();
|
||||||
|
}$0
|
||||||
|
"#,
|
||||||
|
r#"
|
||||||
|
fn foo() {
|
||||||
|
fun_name();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn $0fun_name() {
|
||||||
|
foo();
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn extract_does_not_wrap_res_in_res() {
|
fn extract_does_not_wrap_res_in_res() {
|
||||||
check_assist(
|
check_assist(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue