Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bug in extract_function.rs #16009

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 27 additions & 1 deletion crates/ide-assists/src/handlers/extract_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,12 @@ pub(crate) fn extract_function(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op
_ => format_function(ctx, module, &fun, old_indent, new_indent),
};

if fn_def.contains("ControlFlow") {
// There are external control flows
if fun
.control_flow
.kind
.is_some_and(|kind| matches!(kind, FlowKind::Break(_, _) | FlowKind::Continue(_)))
{
let scope = match scope {
ImportScope::File(it) => ImportScope::File(builder.make_mut(it)),
ImportScope::Module(it) => ImportScope::Module(builder.make_mut(it)),
Expand Down Expand Up @@ -4968,6 +4973,27 @@ pub fn testfn(arg: &mut Foo) {
fn $0fun_name(arg: &mut Foo) {
arg.field = 8;
}
"#,
);
}
#[test]
fn does_not_import_control_flow() {
check_assist(
extract_function,
r#"
//- minicore: try
fn func() {
$0let cf = "I'm ControlFlow";$0
}
"#,
r#"
fn func() {
fun_name();
}

fn $0fun_name() {
let cf = "I'm ControlFlow";
}
"#,
);
}
Expand Down